0
所以在我的tkinter python程序中,当点击一个按钮时,我正在调用一个命令。当发生这种情况时,它会运行一个函数,但是在函数中,我会在第一次单击按钮时为它设置一个标签,之后它应该只更新该标签。基本上在尝试之后,它将尝试更改为1,以确保if语句能够看到并且不允许它通过。但它不断重置,我不知道如何阻止它。当您单击按钮时,无论第一个或第三个按钮是否重置,并且因为h被打印而出现这种情况的证据。就好像该函数重新启动,但它不应该,因为它是GUI的循环。按钮“复位”的命令功能
def fight(): #Sees which one is stronger if user is stronger he gets win if no he gets loss also displays enemy stats and removes used characters after round is finished
try:
attempt=0
namel = ""
namer=""
left = lbox.curselection()[0]
right = rbox.curselection()[0]
totalleft = 0
totalright = 0
if left == 0:
namel = "Rash"
totalleft = Rash.total
elif left==1:
namel = "Untss"
totalleft = Untss.total
elif left==2:
namel = "Illora"
totalleft = 60+35+80
if right == 0:
namer = "Zys"
totalright = Zys.total
elif right==1:
namer = "Eentha"
totalright = Eentha.total
elif right==2:
namer = "Dant"
totalright = Dant.total
lbox.delete(lbox.curselection()[0])
rbox.delete(rbox.curselection()[0])
print(namel)
print(namer)
if attempt == 0:
wins.set("Wins")
loss.set("Loss")
print("h")
attempt=1
if (totalleft>totalright):
wins.set(wins.get()+"\n"+namel)
loss.set(loss.get()+"\n"+namer)
else:
wins.set(wins.get()+"\n"+namer)
loss.set(loss.get()+"\n"+namel)
except IndexError:
pass
对于那些看到我以前的问题,我仍然需要帮助,我也想修复这个bug。