asleniovas
asleniovas

Reputation: 333

how to correctly disable tkinter button

I have assigned a function to my ttk button and I'm trying to disable the button before do_something_else() runs:

def do_something():

    button.config(state='disabled')
    do_something_else()


button = ttk.Button(mainframe, text="Click Me", command=do_something, state="normal")

The above doesn't disable the button until do_something_else() is finished. How do I disable correctly? The behavior I want to achieve is to disable the button -> run do_something_else() - > re-enable the button.

EDIT

Accepted answer is correct, for more details refer to Tkinter Button still responds to click after being disabled and updated

Upvotes: 0

Views: 378

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385830

You can call button.update_idletasks() to force tkinter to refresh the display.

Upvotes: 2

Related Questions