尽管Eli Courtwright的程序可以正常运行¹,但是您似乎真正想要的只是在实例化之后重新配置实例化时可以设置的任何属性的一种方法²。这样做是通过configure()方法实现的。
from Tkinter import Tk, Buttondef 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。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)