UnboundLocalError:局部变量,请告诉我我做错了什么以及如何解决

时间:2019-06-06 09:49:19

标签: python python-3.x

我正在尝试编写游戏代码(我才刚开始使用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()

0 个答案:

没有答案