您的位置:首页 > 编程语言 > Python开发

python开发_tkinter_多级子菜单

2013-09-11 16:19 686 查看
在之前的blog中有提到python的tkinter中的菜单操作

python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐

python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)

python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

python开发_tkinter_复选菜单

python开发_tkinter_单选菜单_不可用菜单操作

下面是tkinter的多级子菜单操作

运行效果:



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

代码部分:

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

from tkinter import *

__author__ = {'name' : 'Hongten',
'mail' : 'hongtenzone@foxmail.com',
'blog' : 'http://www.cnblogs.com/',
'QQ': '648719819',
'created' : '2013-09-10'}

def makeCascadeMenu():
# make menu button
Cascade_button = Menubutton(mBar, text='Cascading Menus', underline=0)
Cascade_button.pack(side=LEFT, padx="2m")

# the primary pulldown
Cascade_button.menu = Menu(Cascade_button)

# this is the menu that cascades from the primary pulldown....
Cascade_button.menu.choices = Menu(Cascade_button.menu)

# ...and this is a menu that cascades from that.
Cascade_button.menu.choices.weirdones = Menu(Cascade_button.menu.choices)

# then you define the menus from the deepest level on up.
Cascade_button.menu.choices.weirdones.add_command(label='avacado', command=lambda:print('hello'))
Cascade_button.menu.choices.weirdones.add_command(label='belgian endive')
Cascade_button.menu.choices.weirdones.add_command(label='beefaroni')

# definition of the menu one level up...
Cascade_button.menu.choices.add_command(label='Chocolate')
Cascade_button.menu.choices.add_command(label='Vanilla')
Cascade_button.menu.choices.add_command(label='TuttiFruiti')
Cascade_button.menu.choices.add_command(label='WopBopaLoopBapABopBamBoom')
Cascade_button.menu.choices.add_command(label='Rocky Road')
Cascade_button.menu.choices.add_command(label='BubbleGum')
Cascade_button.menu.choices.add_cascade(
label='Weird Flavors',
menu=Cascade_button.menu.choices.weirdones)

# and finally, the definition for the top level
Cascade_button.menu.add_cascade(label='more choices',
menu=Cascade_button.menu.choices)

Cascade_button['menu'] = Cascade_button.menu

return Cascade_button

#################################################
#### Main starts here ...
root = Tk()
root.geometry('600x300')

# make a menu bar
mBar = Frame(root, relief=RAISED, borderwidth=2)
mBar.pack(fill=X)

Cascade_button = makeCascadeMenu()

mBar.tk_menuBar(Cascade_button)

root.title('menu demo')
root.iconname('menu demo')

root.mainloop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: