Newbie (faq!): pmw/tkinter menubar command-option

Brian Elmegaard be at et.dtu.dk
Fri Aug 4 05:15:51 EDT 2000


Hi,

probably I should be able to find an answer to this in the introduction
to tkinter/life preserver or in the pmw docs, but I could not manage,
so:

If I create a menubar using pmw in the __init__-method, and assign a
command to it, the command is run once during application startup and is
not available under execution. This is happening only if the function is
called with an argument or an empty argument list. 


The code below act like describd. Why is this happening? How do I avoid
it and where could I have read about it?

Furthermore, how do I convince pmw to add a tearoff to the menu? (The
code below only uses tkinter and does add tearoffs)

# File: menu1.py
from Tkinter import *
def callback(text):
    print "called the callback!"+text
root = Tk()
# create a menu
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=callback('new'))
filemenu.add_command(label="Open...", command=callback('open'))
filemenu.add_separator()
filemenu.add_command(label="Exit", command=callback('exit'))
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=callback('About'))

mainloop()

Thanks for any help
Brian



More information about the Python-list mailing list