想给窗口关闭的时候弹出确认取消的消息框,在外边能运行但是放窗口关闭函数里就不行了 有大佬帮忙看看吗
报了这个 RuntimeError: Calling Tcl from different apartment
[Python] 纯文本查看 复制代码 import ttkbootstrap as ttk
from ttkbootstrap.dialogs import Messagebox
import threading
class TestGui:
def __init__(self, root_window):
self.root_windows = root_window
self.root_windows.title("11111111")
self.root_windows.geometry("380x285")
self.root_windows.protocol('WM_DELETE_WINDOW', lambda: self.thread_it(self.clos_window))
# Messagebox.okcancel(message="确定取消") 正常弹窗
def clos_window(self):
Messagebox.okcancel(message="确定取消") #这就报错了 用self方法也是
# 还没加入判断 只是测试消息框
def thread_it(self, func, *args):
self.myThread = threading.Thread(target=func, args=args)
self.myThread .setDaemon(True)
self.myThread .start()
if __name__ == '__main__':
root_window = ttk.Window()
root_window.attributes("-topmost", 1)
root_window.resizable(width=False, height=False)
test_gui = TestGui(root_window)
root_window.mainloop()
|