def closeEvent(self, event): # класс обязательно должен наследовать от QDialog
if self.trayIcon.isVisible():
QMessageBox.information(self, "Systray",
"The program will keep running in the system tray. To "
"terminate the program, choose <b>Quit</b> in the "
"context menu of the system tray entry.")
self.hide()
event.ignore()
self.trayIcon = QSystemTrayIcon(self)