Tkinter widgets "disable" only after for-loop in callback function

时间:2019-03-17 23:05:20

标签: python tkinter widget

When trying to disable Tkinter widgets immediately after a callback function has been invoked (by clicking a button for example), the widgets only disable after the for-loop in the function has been completed. Example code:

from tkinter import *
import time


def start_forloop():
    for x in range(10):
        time.sleep(1)


def disable_widget():
    button_start.configure(state='disabled')
    entry_test.configure(state='disabled')
    start_forloop()


# Window settings
app = Tk()
app.title('Test')

# Define widgets
button_start = Button(app, width=30, text='Start', command=disable_widget)
entry_test = Entry(app, width=30)

# Pack widgets
button_start.pack()
entry_test.pack()

# Start processing app
app.mainloop()

Is there a way such that the widgets disable before the for-loop ends?

0 个答案:

没有答案