清除Tkinter中的放置标签 [英] Clearing Placed Labels in Tkinter
问题描述
所以我的货币在增加(该系统运行正常).第一部分每100毫秒更新一次标签.我还有另一个按钮可以触发第二个功能,该功能应该从第一个功能清除标签.它将 home_status
设置为等于 0
,理论上应该运行 Money.place_forget()
清除代码.我已经分别测试了每个部件,并且可以正常工作,但是当我将透明部件放入 elif
语句中时,它就没有效果.它不会给我任何错误,它只是什么都不做(它会打印 END OF UPDATE HOME
,因此触发了 elif
).
So I have a currency which is increasing (that system is working fine). The first part updates the label every 100 ms. I have another button which triggers the second function which is supposed to clear the labels from the first. It sets home_status
equal to 0
which should in theory run Money.place_forget()
to clear the code. I have tested each part individually and it works but when I put the clears inside the elif
statement it doesn't. It does not give me any errors, it just simply doesn't do anything (it does print END OF UPDATE HOME
so the elif
is triggered).
有什么建议吗?
def updatehome(self):
print("UPDATE HOME")
global buy_button, home_status, currency
MoneyLabel = Label(self, text = "Money: ")
MoneyLabel.place(x = 5, y = 70)
Money = Label(self, text=currency)
Money.place(x = 50, y = 70)
if (home_status == 1):
self.after(100, self.updatehome)
elif (home_status == 0):
print("END OF UPDATE HOME")
Money.place_forget()
MoneyLabel.place_forget()
def clearhome(self):
print("CLEAR HOME")
global home_status
home_status = 0
推荐答案
您每秒创建十个标签,所有标签都堆叠在一起,但是您只删除了创建的最后一个标签.
you are creating ten labels every second, all stacked on top of each other, but you are only deleting the very last label you create.
这篇关于清除Tkinter中的放置标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!