tkinter menuitem question
Eric Brunel
eric.brunel at pragmadev.com
Wed Mar 20 11:30:33 EST 2002
<posted & mailed>
Ken Guest wrote:
> ok, I might be way off here but is there a way with a collection of
> Tkinter menuitems that all have their callbacks set to be the one
> function to determine which menuitem was clicked on?
AFAIK, you cant't. But a simple workaround is to use a lambda function
(example is in pure Tkinter):
----------------------------------
from Tkinter import *
root = Tk()
def menuHit(menuName): print menuName
menubar = Menu(root)
m = Menu(menubar)
menubar.add_cascade(label='Menu', menu=m)
m.add_command(label="m1", command=lambda: menuHit("m1"))
m.add_command(label="m2", command=lambda: menuHit("m2"))
root['menu'] = menubar
root.mainloop()
----------------------------------
HTH
- eric -
More information about the Python-list
mailing list