我的这段代码显示错误:_tkinter.TclError:unknown option" -command"。我是新手,所以我可能犯了一个愚蠢的错误。请帮忙!
import tkinter
bod = tkinter.Tk()
button = tkinter.Button(bod, text="Hello (Click here)")
def hello():
button = tkinter.Button(bod, text="Hello World!")
button.place(x=10, y=100, height="100", width="100", command=hello)
bod.mainloop()
答案 0 :(得分:0)
你应该这样做:
from tkinter import *
def hello():
button.config(text="Hello, World!")
bod = Tk()
button = Button(bod, text="Hello (Click here)", command=hello, height="100", width="100")
button.pack()
bod.mainloop()
这会对您有所帮助:http://effbot.org/tkinterbook/button.htm#Tkinter.Button.config-method