简体   繁体   English

清除Tkinter中的放置标签

[英]Clearing Placed Labels in Tkinter

So I have a currency which is increasing (that system is working fine). 所以我的货币在增加(该系统运行正常)。 The first part updates the label every 100 ms. 第一部分每100毫秒更新一次标签。 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. 它将home_status设置home_status等于0 ,理论上应该运行Money.place_forget()清除代码。 I have tested each part individually and it works but when I put the clears inside the elif statement it doesn't. 我已经分别测试了每个部分,并且可以正常工作,但是当我将清除内容放入elif语句中时,它就无效了。 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). 它不会给我任何错误,它只是什么都不做(它会打印END OF UPDATE HOME因此触发elif )。

Any suggestions? 有什么建议么?

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

您每秒创建十个标签,所有标签都堆叠在一起,但是您只删除了最后创建的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM