# Creating a window with a menu bar # This creates the menu hierarchy: # # File Hello # |_Open |_Say Hello # |______ # |_Exit # # This code inspired by # http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm from Tkinter import * root = None def hello(): print "hello!" def main(): global root root = Tk() # Just put something in the window lbl = Label(root, text="test") lbl.pack() # create a toplevel menu menubar = Menu(root) # create a pulldown menu, and add it to the menu bar filemenu = Menu(menubar) # Create the file menu filemenu.add_command(label="Open", command=hello) # Add a command filemenu.add_separator() # Add a separator filemenu.add_command(label="Exit", command=root.destroy) # Add another command menubar.add_cascade(label="File", menu=filemenu) # Add the menu to the menubar # Create another menu item named Hello and add to the menu helloMenu = Menu(menubar) helloMenu.add_command(label="Say hello", command=hello) menubar.add_cascade(label="Hello", menu=helloMenu) # display the menu root.config(menu=menubar) root.mainloop() main()