pythonTKinter的消息传递机制
pythonTKinter的消息传递机制
1、自动发送事件/消息。
2、系统负责将消息发送到队列。
3、绑定/设置相关组件。
4、后端自动选择感兴趣的事件并做出相应的反应。
5、消息格式<[modifier-]---type-[-detail]>。
实例
#事件的简单例子
importtkinter
defbaseLabel(event):
globalbaseFrame
print("被点击")
lb=tkinter.Label(baseFrame,text="谢谢点击")
lb.pack()
#画出程序的总框架
baseFrame=tkinter.Tk()
lb=tkinter.Label(baseFrame,text="模拟按钮")
#Label绑定相应的消息和处理函数
#自动获取左键点击,并启动相应的处理函数baseLabel
lb.bind("",baseLabel)
lb.pack()
#启动消息循环
#至此,表示程序开始执行
baseFrame.mainloop()
以上内容为大家介绍了python培训之TKinter的消息传递机制,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python包的导入方式有几种
python包的导入方式有几种本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、from...import导入frompackageimportmodule1,mo详情>>
2023-11-08 23:58:44
python参数是什么
python参数是什么1、概念Python中函数的参数是不变的对象。Python函数具有灵活的参数形式,但默认参数必须指向不变的对象。如果默认参数是可变...详情>>
2023-11-08 19:48:30
python使用items()遍历键值对
python使用items()遍历键值对字典可以用来存储各种方式的信息,所以有很多方式可以通过字典的所有键值对、键或值。说明1、即使通过字典,键值对...详情>>
2023-11-08 19:23:48
python按行读取文件的方法比较
python按行读取文件的方法比较1、read方法默认会把文件的所有内容一次性读取到内存。如果文件太大,对内存的占用会非常严重2、readline方法,re...详情>>
2023-11-08 18:22:27