【发布时间】:2020-11-03 04:30:47
【问题描述】:
所以我的代码中的函数有问题,它没有在控制台中显示失败,所以我只是不知道出了什么问题。 基本上我试图做一个点击器有点像每次点击按钮时都会将 exp 变量增加一个然后更新标签,但它并没有真正起作用。关卡部分也不需要太多关注,除非你有什么想说的。
window = Tk()
window.title ("test")
#variables
exp2 = 0
level = 1
exp = 0
#exp function
def function ():
global exp,exp2, level
exp2 = exp + 1
if exp <100:
exp = 0
level + 1
else:
return function()
#labels
label_1 = Label (window, text = (exp2,"/100"), bg = 'white', fg ='black')
label_2 = Label (window, text = "exp" , bg = 'white', fg ='black')
label_3 = Label (window, text = "level", bg = 'white', fg ='black')
label_4 = Label (window, text = level, bg = 'white', fg ='black')
#buttons
button_1 = Button (window, text = 'click for xp', command = function())
#placements
label_1.grid (column = 3, row = 2)
label_2.grid (column = 3, row = 1)
label_3.grid (column = 5 , row = 1)
label_4.grid (column = 5, row = 2)
button_1.grid (column = 4, row = 4 )
window.mainloop()
【问题讨论】:
-
command=function()应该是command=function(没有())。再想想function()里面的逻辑。