Adding a menu to Tkinter

Ronn Ross ronn.ross at gmail.com
Mon Oct 26 21:56:32 EDT 2009


I'm attempting to add a menu bar to my Tkinter app. I can't figure out the
correct syntax. Can someone help?  I get this error when I run the app:

Traceback (most recent call last):
  File "tkgrid.py", line 26, in <module>
    app = App(root)
  File "tkgrid.py", line 10, in __init__
    menubar = Menu(master).grid(row=0)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py",
line 1859, in grid_configure
    + self._options(cnf, kw))
_tkinter.TclError: can't manage ".4300345712": it's a top-level window


from Tkinter import *

class App:

    def __init__(self, master):

        def hello():
            print "hello!"

        menubar = Menu(master).grid(row=0)
        menubar.add_command(label="Hello!", command=hello)
        Label(master, text="First").grid(row=1)
        Label(master, text="Second").grid(row=2)

        e1 = Entry(master)
        e2 = Entry(master)
        e3 = Entry(master)

        e1.grid(row=0, column=1)
        e2.grid(row=1, column=1)
        e2.grid(row=2, column=1)


root = Tk()

app = App(root)

root.mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091026/0bad372e/attachment.html>


More information about the Python-list mailing list