Adding a menu to Tkinter

Ronn Ross ronn.ross at
Tue Oct 27 02:56:32 CET 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 "", line 26, in <module>
    app = App(root)
  File "", line 10, in __init__
    menubar = Menu(master).grid(row=0)
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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list