Let's create a button and first beginning:
% set imgfile "/usr/lib/icon/test1.gif"
% image create myimg -file $imgfile
% button .bt1 -image myimg
% pack .bt1
Now, therte shows up a button with image inside.
% set imgfile1 "/usr/lib/icon/test2.gif"
% myimg read $imgfile1
so the picture changed as myimg linked to another image file.
type in "myimg configure" you can see all the options the myimg has: -data -format -file -gamma -height -palette -width.
We can back to the button widget then.
Entry ".bt1 configure" you can get all options for button widget.
Time to see how we can change what button looks like.
% .bt1 configure -text "Hi there!"
This time, we see nothing changed. text doesn't show up. What's wrong?
Don't worry, try this as well.
% .bt1 configure -compound bottom
you see it? text shows up on the top of the picture.
Ok, we can try to make the button do something for us.
% .bt1 configure -command {exec ls -l}
a simple function just list files.
Click the button, Nothing happens.eh?
go on...
% .bt1 invoke
haha, file listed here. but try to click the button, still nothing happens. don't worry, keep going.
% bind .bt1 《h> { .bt1 configure -text "I'm changed."}
seems ok, lick out the button window and press "h", nothing happen. why? supposed the text should changed. just going to add other tow functions:
% bind .bt1 《Button-1> { .bt1 configure -text "Left button pressed."}
% bind .bt1 《Button-3> { .bt1 configure -text "Right button pressed."}
% pack .bt1
(Other two common used events are 《 Enter> and 《Leave>, you can guess it easily)
now, pop up the .bt1 button, lefy click, text changed to "Left button pressed."
yeah, it's worked now. right click,"Right button pressed." , everything seems work now. but why the key "h" doesn't work?
press tab to make .bt1 active, then press "h", what do you get now????
yeah~~~, text is :"I'm changed."
now let's see the configure again:
% .bt1 configure
all parameters there. but no bind information, why?
try this:
% bind .bt1
oh...it's here listed as:
《Button-3《Button-1> h
that's the easy and powerful button!
Posted by John Z