Popup menus in Tkinter
Dieter Maurer
dieter at handshake.de
Wed Nov 10 14:16:49 EST 1999
dkaznadzey at my-deja.com writes on Mon, 08 Nov 1999 19:44:16 GMT:
> What would be a good source of information on tk commands
> available through Tkinter?
I use "tclhelp", a program with comes with "tclX".
It is a grafical documentation program for "tcl", "tclX"
and "tk". Alternatively, you can use the online tcl/tk
documentation (e.g. from scriptics).
These, of cause, document "tcl/tk" not "Tkinter".
However, the mapping from "tk" to "Tkinter" is quite straight forward:
* If a widget "w" supports a command "c" with positional parameters
"p1", "p2", ... and option value pairs "o1", "v1", "o2", "v2", ...,
then the corresponding "Tkinter" object "W" usually has a method "c"
which can be called: W.c(p1,p2,..., o1=v1, o2=v2, ...)
Examples:
a text widget "t" supports the "insert" command with
parameters "index", "chars" and optionally "taglist",
"chars", "taglist", "chars" and so on.
So one can call:
t insert end Hello tag1 'Bye' {tag2 tag3}
For the corresponding Tkinter object "T", this looks like:
T.insert('end','Hello','tag1','Bye',['tag2','tag3'])
the "configure" command of a widget may take several
forms:
a) w configure
b) w configure -option
c) w configure -option1 value1 -option2 value2 ...
In Tkinter, this looks like:
a) w.configure()
b) w.configure('option')
c) w.configure(option1=value1, option2=value2, ...)
* If a widget "w" has "subobjects" of type "s" which supports
command "c", then the corresponding "Tkinter" method
is "W.s_c".
Positional parameters and keyword parameters (option,value pairs
in tcl) are handled as shown above.
Example:
a text widget "t" has "tag" subobjects supporting e.g.
the command "bind".
The "Tkinter" method is "T.tag_bind".
* Tk control commands (e.g. "pack", "bind", "grid", wm, winfo, ...)
are mapped to corresponding method calls of the first slave.
Examples:
a) pack slave1 slave2 .... -option1=value1 -option2=value2 ...
b) grid slave -option1=value1 ...
become in Tkinter:
a) slave1.pack(option1=value1, option2=value2, ...)
slave2.pack(option1=value1, option2=value2, ...)
....
b) slave.grid(option1=value1, ...)
A sub-commands "s" of a control command "c" is mapped to
the method "s_c".
Example:
pack forget slave1 slave2 ...
becomes:
slave1.pack_forget()
slave2.pack_forget()
....
There are few exceptions from the rules stated above, e.g.:
* additional parameter "add" for the various forms of "bind"
to tell Tkinter to add a function to the action list
(or replace the action list).
* special handling of variables (e.g. bound to buttons):
they must be created as Tkinter objects while in
tcl/tk creation is automatic.
- Dieter
More information about the Python-list
mailing list