Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何向嵌入在按钮中的事件添加更多信息。
例如:
okButton = ttk.Button( content, text = 'OK' ) okButton.bind( "<Button-1>", browseFile ) def browseFile( event ): pass
单击按钮时,我想将字符串参数“确定”传递给函数browseFile,我需要做什么?
browseFile
谢谢
该event对象有一个widget成员,该成员标识引发事件的小部件。cget您可以使用以下方法获取该小部件的文本:
event
widget
cget
def browseFile(event): buttonText = event.widget.cget("text") if buttonText == "OK": doSomeStuff()