| Widgets/Button |
UserPreferences |
| Tkinter Wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
A button is a widget that displays a textual string, bitmap or image. If text is displayed, it must all be in a single font, but it can occupy multiple lines on the screen (if it contains newlines or if wrapping occurs because of the wraplength= option) and one of the characters may optionally be underlined using the underline option. It can display itself in either of three different ways, according to the state. to disable a button set state = DISABLED. To enable set state = NORMAL. Tk sets state = ACTIVE when mouse is over a non-DISABLED button) option; it can be made to appear raised, sunken, or flat; and it can be made to flash. When a user invokes the button (by pressing mouse button 1 with the cursor over the button), then the command specified in the command= option is invoked. If the command is a callable object, it is called with no arguments. If it is a string, it is executed as Tcl code.
If the button's state is disabled then none of the above actions occur: the button is completely non-responsive. The behavior of buttons can be changed by defining new bindings for individual widgets or by redefining the class bindings.
Just giving a button default="active" doesn't create a binding for <Return> (the enter key). See
http://wiki.tcl.tk/534 and search for "-default active" for some Tcl code related to this.
The standard Button widget does not allow parameters to be passed by the command method. This can be circumvented by re-writing the method as below:
1 2 3 4 | def command(func, *args, **kw):
def _wrapper(*wargs):
return func(*(wargs + args), **kw)
return _wrapper |
Newcomers to Tkinter frequently ask about passing parameters through a button selection. The wrapper command above, supplied by Guilherme Polo, can be used as ... It's a clever alternative to Tkinter's more traditional style as expressed by
Bob Greschke, for example.