0

I'm programming an app in Python that should run processes in the background. In order to be able to control this, I implemented a systray icon. The systray-icon should also be able to open a user interface that I wrote with PyQt5. If you close the systray icon, the entire program, including the GUI, should be terminated.

The problem is that either the GUI or the systray icon keeps getting stuck. I've tried threading but am getting stuck as the GUI must always run on the main thread. Here is my code:

from PyQt5.QtWidgets import *
import sys
import threading
from infi.systray import SysTrayIcon


app = QApplication(sys.argv)
window = QMainWindow()

def startGUI(systray):
    window.show()
    sys.exit(app.exec_())

def shutdownGUI(systray):
    sys.exit(app.exec_())

def test(systray):
    pass

systray_options = (("Open GUI", None, startGUI), ("Test", None, test))
systray_icon = SysTrayIcon("icon.ico", "MyApp", systray_options, on_quit=shutdownGUI)


if __name__ == "__main__":
    systray_icon.start()
Benedikt
  • 1
  • 4

0 Answers0