Menubutton: 菜单按钮控件,用于显示菜单项。
一、基本使用
1、制作一个Menubutton菜单
代码如下:
# coding:utf8 from tkinter import * # 制作Menubutton class App: def __init__(self, master): frame = Frame(master).pack() # 实例化一个Menubutton对象, 可以把它理解为纯粹的button按键,只是这个能绑定菜单。 mb = Menubutton(frame, text="我是菜单", relief=RAISED) mb.pack(padx=10, pady=10) # 实例化一个menu对象,添加菜单 menubutton = Menu(mb, tearoff=False) menubutton.add_command(label="打开") menubutton.add_command(label="保存") menubutton.add_command(label="退出", command=root.quit) # 绑定 mb.config(menu=menubutton) root = Tk() win = App(root) root.mainloop()
效果如下:
点击按钮,出现一个菜单,就是Menubutton。
读书和健身总有一个在路上