pythonTKinter弹出式菜单的使用
1、弹出菜单也叫上下文菜单,建立菜单并向菜单添加各种功能。
2、右键监听鼠标。如右键点击,则根据位置判断弹出。
3、调用Menupop方法。
4、add_separator添加分隔符。
实例
#弹出式菜单案例
importtkinter
defmakeLabel():
globalbaseFrame
tkinter.Label(baseFrame,text="PHP是最好的编程语言,我用Python").pack()
baseFrame=tkinter.Tk()
menubar=tkinter.Menu(baseFrame)
forxin['麻辣香菇','汽锅鸡','东坡肘子']:
menubar.add_separator()
menubar.add_command(label=x)
menubar.add_command(label="重庆火锅",command=makeLabel)
#事件处理函数一定要至少有一个参数,且第一个参数表示的是系统事件
defpop(event):
#注意使用event.x和event.x_root的区别
#menubar.post(event.x,event.y)
menubar.post(event.x_root,event.y_root)
baseFrame.bind("",pop)
baseFrame.mainloop()
以上内容为大家介绍了python培训之TKinter弹出式菜单的使用,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
pythonPython的应用领域
Python的应用领域主要有如下几个。Web应用开发Python经常被用于Web开发。例如,通过mod_wsgi模块,Apache可以运行用Python编写的Web程序。Pytho...详情>>
2023-11-08 23:44:23
pythoncollections.Counter的计数
pythoncollections.Counter的计数1、说明Counter类型中的计数器还支持负值。通过简单的+-作为Counter类型对象的前缀,就可以实现正负计数过滤。...详情>>
2023-11-08 22:44:16
python包的导入方式有几种
python包的导入方式有几种本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、from...import导入frompackageimportmodule1,mo详情>>
2023-11-08 21:33:52
python继承的特征有哪些?
python继承的特征有哪些?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、概念继承就是一个类可以获得另外一个类中的成员属性和...详情>>
2023-11-08 19:55:46热门推荐
pythonPython的应用领域
沸python的三引号怎么输入
热pythoncollections.Counter的计数
热python使用Dockerfile构建镜像
新python包的导入方式有几种
pythonplot()函数的基本介绍
pythonAllure框架是什么?
python继承的特征有哪些?
python类方法的注意点
pythonpickle模块在Python的函数使用
python列表运算详解
pythonautoenv怎么用
pythonpyqt5复选框怎么用?
python如何对Python数据表进行检查
技术干货






