# Creating a window with a menu bar # # 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) filemenu.add_command(label="Open", command=hello) filemenu.add_command(label="Save", command=hello) filemenu.add_separator() filemenu.add_command(label="Exit", command=root.destroy) menubar.add_cascade(label="File", menu=filemenu) # Create another menu item named Hello helloMenu = Menu(menubar) helloMenu.add_command(label="Say hello", command=hello) menubar.add_cascade(label="Hello", menu=helloMenu) # Create a submenu under the Hello Menu subHello = Menu(helloMenu) # My parent is the helloMenu subHello.add_command(label="English", command=hello) # Menu Item 1 subHello.add_command(label="Spanish", command=hello) # Menu Item 2 subHello.add_command(label="Chinese", command=hello) # Menu Item 3 subHello.add_command(label="French", command=hello) # Menu Item 4 # Add sub menu into parent with the label International Hello helloMenu.add_cascade(label="International Hello", menu=subHello) # display the menu root.config(menu=menubar) root.title = "Menu Test" root.mainloop() main()