【发布时间】:2022-01-07 15:08:50
【问题描述】:
我用 PysimpleGUI 创建了一个有多个按钮的 GUI,其目的是用户单击一个按钮并在第一个单击按钮的操作正在运行时继续处理其他任务,以及当单击按钮的操作时完成,然后线程退出(破坏当前线程),
代码抛出:RuntimeError: 主线程不在主循环中
有人可以帮我创建 _thread.start_new_thread 进程并合并到主循环中,或者可能是避免 RuntimeError 的解决方案
我正在使用的线程:_thread
代码:
class Windows:
def newOpenGraph(self, window, event, values):
'''
opens a new graph with no problem
'''
def newThread(self, window, event, values):
isRunning = True
if event == 'OPEN GRAPH':
_thread.start_new_thread(self.newOpenGraph, (window, event, values ))
isRunning = False
while isRunning:
schedule.run_pending()
time.sleep(1)
def mainLayout(self):
'''
layout frame work
'''
while True:
event, values = window.read()
if event == 'OPEN GRAPH':
# self.newOpenGraph(window, event, values)
self.newThread(window, event, values)
图片:
【问题讨论】:
标签: loops main tk pysimplegui