问题
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