You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nested tkinter mainloop() resets the dispatching flag of the outer mainloop() #162650
3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixestopic-tkintertype-bugAn unexpected behavior, bug, or error
mainloop() sets a flag which tells that the interpreter dispatches events, so that calls from other threads can be passed to it. But a nested mainloop() resets this flag when it exits, even if the outer mainloop() is still running. After that, calls from other threads fail with RuntimeError: main thread is not in main loop.
A nested mainloop() is run, for example, by SimpleDialog.go() in tkinter.simpledialog and FileDialog.go() in tkinter.filedialog.
importthreading, tkinterroot=tkinter.Tk()
defcall_from_thread():
try:
print(root.tk.call('expr', '6*7'))
exceptRuntimeErrorase:
print('RuntimeError:', e)
defstart():
root.after(100, root.quit) # stop the nested looproot.mainloop() # nested loop, as in SimpleDialog.go()threading.Thread(target=call_from_thread).start()
root.after(2000, root.quit)
root.after(0, start)
root.mainloop()
Output:
RuntimeError: main thread is not in main loop
mainloop() should restore the previous value of the flag when it exits.
3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixestopic-tkintertype-bugAn unexpected behavior, bug, or error
Activity
gh-162650: Fix tkinter calls from other threads after a nested mainlo…
[3.14] gh-162650: Fix tkinter calls from other threads after a nested…
[3.15] gh-162650: Fix tkinter calls from other threads after a nested…