I've been trying out python GUI frameworks for a multithreaded project that requires the GUI to run entirely on a thread started from the main thread with a reference to a variable being updated on a different thread. However, when I run the GUI on a thread other than the main one it instantly closes and I get
"QApplication::exec: Must be called from the main thread"
when using pyqt5 and
"RuntimeError: main thread is not in main loop"
when using tkinter.
I was wondering if anyone knew another python GUI framework that would let me run it on a thread other than the main thread or if there is a way to work around this errors.
Here is an example replicating the first message with pyqt5
import threading, sys
from PyQt5.QtCore import QObject
from PyQt5.QtWidgets import QMainWindow, QApplication
class Example(QMainWindow):
def __init__(self, app):
super().__init__()
self.app=app
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Example')
self.show()
def principal(self):
sys.exit(self.app.exec_())
def main():
app = QApplication(sys.argv)
example = Example(app)
#sys.exit(example.app.exec_())
exampleThread = threading.Thread(target=example.principal, name='example')
exampleThread.start()
main()