虽然Eli Courtwright的程序运行良好¹,但你真正想要的只是一种在实例化后重新配置任何属性的方法,你可以在实例化时设置它。你是如何通过configure()方法实现的。from Tkinter import Tk, Button
Python tkinter。def goodbye_world():
print "Goodbye World!\nWait, I changed my mind!"
button.configure(text = "Hello World!", command=hello_world)
def hello_world():
print "Hello World!\nWait, I changed my mind!"
button.configure(text = "Goodbye World!", command=goodbye_world)
root = Tk()
button = Button(root, text="Hello World!", command=hello_world)
button.pack()
root.mainloop()
如果你只使用鼠标,¹“很好”; 如果您关心标签并使用按钮上的[Space]或[Enter],那么您还必须实现(复制现有代码)按键事件。command通过设置选项.configure要容易得多。
²实例化后唯一不能改变的属性是name。
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态