[英]Python - Tkinter... Can't update GUI status bar --> i want to update message 2 times when button clicked
[英]Can't update the value of i by clicking the button in python tkinter
我在这个答题器代码中找不到那个错误。 i 变量不会通过单击“单击”按钮进行更新。 如果您发现错误,请通知我。 谢谢!
from tkinter import *
root = Tk()
i = 0
def numberchanger():
i = i + 1
clicker = Button(text="click", bg="red", fg="green", font="Arial 20 bold", command=numberchanger)
clicker.place(x=600, y=400)
widget.title("Clicker")
clicknumber = Label(text=i, fg="blue", font="Arial 50 bold")
clicknumber.place(x=600, y=200)
root.mainloop()
在def numberchanger():
之后添加一个global i
:
from tkinter import *
root = Tk()
i = 0
def numberchanger():
global i
i = i + 1
print(i)
clicknumber.config(text=i)
clicknumber = Label(text=i, fg="blue", font="Arial 50 bold")
clicknumber.place(x=600, y=200)
clicker = Button(text="click", bg="red", fg="green", font="Arial 20 bold", command=numberchanger)
clicker.place(x=600, y=400)
clicker.pack()
clicknumber.pack()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.