我正在尝试编写游戏代码(我才刚开始使用Tkinter),但这一直在弹出
UnboundLocalError:分配前引用了本地变量'money'
这是我尝试的代码:
from tkinter import *
root = Tk()
money = 0
click = 1
def earnmoney():
money = money + click
def showmonney():
Total_money.configure(text = money)
root.title("MONEY")
root.geometry("1000x500")
app = Frame(root)
app.grid()
label = Label(app, text = "Press the button to earn money")
label.grid()
button1 = Button(app, text = "Earn money", command=earnmoney)
button1.grid()
button2 = Button(app, text = "Show money", command=showmonney)
button2.grid()
Total_money = Label(app)
Total_money.grid()
root.mainloop()