我正在制作一个基本的tkinter程序,该程序将更改标签的文本。 当程序运行时,它已经说“你点击了按钮!”而按钮没有点击。请注意,我没有点击它。
此外,我尝试使用其他命令,如print(“”),但程序会在程序开始时自动打印所写的内容。
这是我的代码
from tkinter import * Window = Tk() Window.title("Button on Click") Window.geometry("350x350") Label1 = Label(Window, text="Click the button") Label1.grid(column=2, row=1) def Click(): Label1.configure(text="You clicked the button!") Label1.grid(column=2, row=1) Button1 = Button(Window, text="Surprise!", fg="blue", command=Click()) Button1.grid(column=1, row=1) Window.mainloop()
你拨打了的命令
Button1 = Button(Window, text="Surprise!", fg="blue", command=Click())
我认为应该去掉括号
Button1 = Button(Window, text="Surprise!", fg="blue", command=Click)