Skip to content Skip to sidebar Skip to footer

Disable Tkinter Button While Executing Command

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 impo

Solution 1:

Use pack_forget() to disable and pack() to re-enable. This causes "pack" window manager to temporarily "forget" it has a button until you call pack again.

from Tkinter import *
import time

top = Tk()
defRun(object):
    object.pack_forget()
    print'test'
    time.sleep(5)
    object.pack()

b1 = Button(top, text = 'RUN', command = lambda : Run(b1))
b1.pack()

top.mainloop()

Solution 2:

You need

object.config(state = 'disabled')
b1.update()
time.sleep(5)
object.config(state = 'normal')
b1.update()

to update the button and pass execution back to Tkinter.

Post a Comment for "Disable Tkinter Button While Executing Command"