Menu action : Menu « GUI Tk « Python






Menu action

Menu action
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)

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.Add menu to a windowAdd menu to a window
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