Clearing Placed Labels in Tkinter

风流意气都作罢 提交于 2021-02-08 10:25:55

问题


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).

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

回答1:


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.



来源:https://stackoverflow.com/questions/45991567/clearing-placed-labels-in-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!