What i expect to happen:
What actually happens:
Also the button is not only not being destroyed but it seems like the entire window is freezing.
from tkinter import *
import time
count = 5
window = Tk()
def func():
global count
button.destroy() #This should destroy the button but it stays there until the while loop is finished
while count > 0:
print(count)
count = count - 1
time.sleep(1)
quit()
button = Button(text="text", command=func)
button.pack()
window.mainloop()
You can call the update()
method and then the button will be deleted first.
from tkinter import *
import time
count = 5
window = Tk()
def func():
global count
button.destroy() #This should destroy the button but it stays there until the while loop is finished
window.update()
while count > 0:
print(count)
count = count - 1
time.sleep(1)
quit()
button = Button(text="text", command=func)
button.pack()
window.mainloop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.