2
我有一些奇怪的問題與PyQt5
應用程序創建。關閉窗口會殺死整個應用程序,但我不需要它,因爲我也有一個托盤圖標。我在Debian上運行python3,但我認爲它不重要。PyQt窗口關閉關閉整個應用程序
有一個C#的解決方案。 Close a windows form without exiting the entire application 創建另一個表單,但不顯示它。 PyQt
可以嗎?
import sys
import PyQt5.QtWidgets
class SettingsMenu(PyQt5.QtWidgets.QDialog):
def __init__(self, parent):
super().__init__()
self.setWindowTitle("Settings")
self.resize(300, 200)
class ContextMenu(PyQt5.QtWidgets.QMenu):
def __init__(self):
super().__init__()
self.settings_action = self.addAction('Settings')
self.settings_action.triggered.connect(self.display_settings_menu)
def display_settings_menu(self, event):
self.settings_menu = SettingsMenu()
self.settings_menu.show()
class TrayIcon(PyQt5.QtWidgets.QSystemTrayIcon):
def __init__(self):
super().__init__()
self.setIcon(PyQt5.QtGui.QIcon('icon.xpm'))
self.setContextMenu(ContextMenu())
if __name__ == '__main__':
app = PyQt5.QtWidgets.QApplication(sys.argv)
tray_icon = TrayIcon()
tray_icon.show()
sys.exit(app.exec_())