zoukankan      html  css  js  c++  java
  • python开发_tkinter_多级子菜单

    在之前的blog中有提到python的tkinter中的菜单操作

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

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

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

    python开发_tkinter_复选菜单

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

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

    运行效果

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

    代码部分:

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

     1 from tkinter import *
     2 
     3 __author__ = {'name' : 'Hongten',
     4               'mail' : 'hongtenzone@foxmail.com',
     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()
  • 相关阅读:
    第二次作业
    第一次作业
    2019春总结作业
    2019春第四次课程设计报告
    2019春第三次课程设计报告
    2019春第二次课程设计报告
    2019春第一次课程设计报告
    第十二周作业
    2019第十一周作业
    2019第十周作业
  • 原文地址:https://www.cnblogs.com/hongten/p/hongten_python_tkinter_choices_menu.html
Copyright © 2011-2022 走看看