[英]PySimpleGui throwing error when i try to login my bot
我正在为一个应用程序编写一个机器人管理器,但我一直收到这个错误,我没有使用线程库,也没有使用工作线程:
log_msg = self.ui_element.get()
File "C:\Users\derri\AppData\Local\Programs\Python\Python38\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 3515, in get
value = str(self.TKText.get(1.0, tk.END))
File "C:\Users\derri\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 3706, in get
return self.tk.call(self._w, 'get', index1, index2)
RuntimeError: main thread is not in main loop`
function:
def emit(self, record):
# Get the current logs
log_msg = self.ui_element.get()
# Format the log record and append
log_msg += self.format(record)
print(record)
# Update the UI element with the log message
self.ui_element.update(log_msg)
ui_handler = UiLogHandler(window["logs"])
logging.getLogger().addHandler(ui_handler)
方法emit
未在主循环或主线程中调用,因此不要在此方法中更新 GUI 元素,将其替换为方法Window.write_event_value
以生成事件以更新事件循环中的 GUI 元素,例如
def emit(self, record):
# Get the current logs
log_msg = self.ui_element.get()
# Format the log record and append
log_msg += self.format(record)
print(record)
# Update the UI element with the log message
self.window.write_event_value('Update', log_msg)
在你的事件循环中
if event == 'Update':
log_msg = values[event]
ui_element.update(log_msg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.