[Tkinter-discuss] using list elements in menu construction?

Jeff Epler jepler at unpythonic.net
Tue Mar 1 15:55:42 CET 2005

I don't see what's wrong with your program, but a simple Tkinter program
not using pmw seems to work just as expected on my system.

It seems like it would be hard for Python/PMW/Tkinter to even know that
a particular option for varible= was computed by a list indexing
operation, as opposed to any other way.

Whatever problem is in your code, I think you may not have identified it


import Tkinter

# Create widgets
t = Tkinter.Tk()
m = Tkinter.Menu(t); t.configure(menu=m)
menu = Tkinter.Menu(m); m.add_cascade(menu=menu, label="Radiobuttons")
opts = [Tkinter.IntVar() for i in range(15)]

# Callback when checkbutton clicked
def print_opts():
    for i in range(15):
        print "Checkbutton %d: %d" % (i, opts[i].get())

# Populate the checkbutton menu
for i in range(15):
    menu.add_checkbutton(variable=opts[i], label="Checkbutton %d" % i,

# Run the application
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050301/b1601f8c/attachment.pgp

More information about the Tkinter-discuss mailing list