I want to disable tk inter button when executing command and enable it back once the command execution finished. I have tried this code, but it seems not working.
from Tkinter import *
import time
top = Tk()
def Run(object):
object.config(state = 'disabled')
print 'test'
time.sleep(5)
object.config(state = 'normal')
b1 = Button(top, text = 'RUN', command = lambda : Run(b1))
b1.pack()
top.mainloop()
The command execution run well, but every time I click the button when the command is being executed, 'test' appears in the console right after the Run function finished. Which mean the button is not disabled when the Run function is being executed. Any suggestion to fix this problem?
Thanks in advance
sleepas a placeholder for what you really want to do is a poor choice.sleepcauses the whole gui to freeze. What are you really doing? A long calculation? A long database query?