Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter: cannnot create messagebox in a thread

I'm a beginner at Tkinter. Yesterday, when I try to start a message box in a thread function, but it failed and stuck. I didn't find any useful information about this problem, so I asked here:

from tkinter import *
from threading import Thread

def func():
    messagebox.askyesno()

t = Thread(target=func)

Label(text='Hello').pack()

t.start()
mainloop()

No error. it just doesn't work. I also find that any dialog can not be created in the thread procedure.

Thanks for any help, or useful information.

like image 697
Hope Avatar asked Dec 20 '25 06:12

Hope


1 Answers

You cannot call a tkinter widget method from any thread other than the one it was created in, and you can only ever create widgets in a single thread.

like image 157
Bryan Oakley Avatar answered Dec 24 '25 01:12

Bryan Oakley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!