Run Python code from PyQt event loop

I am testing a gui built using PyQt, and I would like to be able to interact with gui using the python code that runs after the PyQt event loop (app.exec_ ()) is triggered. Another way of saying this, I would like the call to app.exec_ to return immediately, as if gui were not modal, and then further python code that interacts with gui.

I found this example of starting a PyQt loop in a stream, but I don't want to do something so unconventional. Is there a way to get the PyQt message loop to continue processing messages, as well as execute python code in the main thread after calling exec_?

+3
source share
4 answers

I understood. I can execute the test script in turn from the main thread using exec and then run gui from the workflow.

0
source

Not quite sure what you want to do. Are you looking for something like Py (known as PyCrust) for PyQt?

0
source

QtCore.QTimer.singleShot() python `exec _() '.

:

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    # Setup the GUI.    
    gui = MyGui()
    gui.showMainWindow()

    # Post a call to your python code.
    QtCore.QTimer.singleShot(1000, somePythonFunction)

    sys.exit(app.exec_()) 

somePythonFunction() 1 . , ​​ .

0

- IPython:

ipython --gui=qt4

See ipython --helpor online documentation for more options (e.g. gtk, tk, etc.).

0
source

Source: https://habr.com/ru/post/1789892/


All Articles