I used tkinter to create a button and assigned a function to it using command
parameter. But this function contains some code takes time to execute. I have simulated it here using time.sleep()
. I want to remove this button when this button is clicked. For this I called the global variable for button inside the function and then used pack_forget()
.
from tkinter import *
import time
def signIn():
global login_button
login_button.pack_forget()
# code after this takes some time to run.
time.sleep(10)
login_screen = Tk()
login_button = Button(login_screen, text="Login", width=10, height=1, command=signIn)
login_button.pack()
login_screen.mainloop()
But the problem is that button gets removed only after the function execution is complete (i.e after 10 seconds). Is there any way I can get the button removed as soon as the pack_forget()
line gets executed and not wait for the full function to complete execution?