Python development _tkinter_ multistage menu

Mention Python Tkinter in the menu operation before blog

Python development _tkinter_ window control _ to produce their own Python IDEL_ blogger recommended

Python development _tkinter_ window control _ to produce their own Python IDEL_ blogger recommended (two)

Python development _tkinter_ menu option to switch _ English menu option is not available _ blogger recommended operation

Python development _tkinter_ check menu

Python development of _tkinter_ radio menu _ not available menu operation

Below is the Tkinter multistage menu operation

Effect of operation:

==========================================================

Part of the code:

==========================================================

 1 from tkinter import *
 2 
 3 __author__ = {'name' : 'Hongten',
 4               'mail' : '',
 5               'blog' : 'http://www.cnblogs.com/',
 6               'QQ': '648719819',
 7               'created' : '2013-09-10'}
 8 
 9 def makeCascadeMenu():
10     # make menu button
11     Cascade_button = Menubutton(mBar, text='Cascading Menus', underline=0)
12     Cascade_button.pack(side=LEFT, padx="2m")
13 
14     # the primary pulldown
15     Cascade_button.menu = Menu(Cascade_button)
16 
17     # this is the menu that cascades from the primary pulldown....
18     Cascade_button.menu.choices = Menu(Cascade_button.menu)
19 
20     # ...and this is a menu that cascades from that.
21     Cascade_button.menu.choices.weirdones = Menu(Cascade_button.menu.choices)
22 
23     # then you define the menus from the deepest level on up.
24     Cascade_button.menu.choices.weirdones.add_command(label='avacado', command=lambda:print('hello'))
25     Cascade_button.menu.choices.weirdones.add_command(label='belgian endive')
26     Cascade_button.menu.choices.weirdones.add_command(label='beefaroni')
27 
28     # definition of the menu one level up...
29     Cascade_button.menu.choices.add_command(label='Chocolate')
30     Cascade_button.menu.choices.add_command(label='Vanilla')
31     Cascade_button.menu.choices.add_command(label='TuttiFruiti')
32     Cascade_button.menu.choices.add_command(label='WopBopaLoopBapABopBamBoom')
33     Cascade_button.menu.choices.add_command(label='Rocky Road')
34     Cascade_button.menu.choices.add_command(label='BubbleGum')
35     Cascade_button.menu.choices.add_cascade(
36         label='Weird Flavors',
37         menu=Cascade_button.menu.choices.weirdones)
38 
39     # and finally, the definition for the top level
40     Cascade_button.menu.add_cascade(label='more choices',
41                                     menu=Cascade_button.menu.choices)
42 
43     Cascade_button['menu'] = Cascade_button.menu
44 
45     return Cascade_button
46 
47 
48 #################################################
49 #### Main starts here ...
50 root = Tk()
51 root.geometry('600x300')
52 
53 
54 # make a menu bar
55 mBar = Frame(root, relief=RAISED, borderwidth=2)
56 mBar.pack(fill=X)
57 
58 
59 Cascade_button = makeCascadeMenu()
60 
61 mBar.tk_menuBar(Cascade_button)
62 
63 
64 root.title('menu demo')
65 root.iconname('menu demo')
66 
67 root.mainloop()

Posted by Samson at November 12, 2013 - 11:11 PM