Add menu to a window : Menu « GUI Tk « Python






Add menu to a window

Add menu to a window
from Tkinter import *

def callback():
    print "called the callback!"

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)
filemenu.add_command(label="Open...", command=callback)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=callback)

helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=callback)

mainloop()


           
       








Related examples in the same category

1.A big menu bar
2.Set up menu and add action to it
3.Disable a menu itemDisable a menu item
4.Set menu item font
5.Menu item mouse on (active) foreground colorMenu item mouse on (active) foreground color
6.Underline for menu item textUnderline for menu item text
7.Menu separatorMenu separator
8.Cascade MenuCascade Menu
9.Disable a menuDisable a menu
10.Creating a small menuCreating a small menu
11.Menu separator 2 and menu action
12.Menu actionMenu action
13.A Simple Form with Menu
14.Three Menu inside a formThree Menu inside a form
15.Framework for a single document interfaceFramework for a single document interface
16.3 popup windows with menus3 popup windows with menus
17.Menu/tool bars packed before middleMenu/tool bars packed before middle