| 22 | class Window(QWidget): |
| 23 | |
| 24 | def __init__(self, *args, **kwargs): |
| 25 | super(Window, self).__init__(*args, **kwargs) |
| 26 | layout = QHBoxLayout(self) |
| 27 | layout.addWidget(QPushButton('开始闪烁', self, clicked=self.start_flash)) |
| 28 | layout.addWidget(QPushButton('停止闪烁', self, clicked=self.stop_flash)) |
| 29 | # 创建托盘图标 |
| 30 | self.tray_icon = QSystemTrayIcon(self) |
| 31 | self.tray_icon.setIcon(self.style().standardIcon( |
| 32 | QStyle.SP_ComputerIcon)) |
| 33 | self.tray_icon.show() |
| 34 | # 图标闪烁定时器 |
| 35 | self.tray_visible = True |
| 36 | self.flash_timer = QTimer(self, timeout=self.flash_icon) |
| 37 | |
| 38 | def closeEvent(self, event): |
| 39 | self.stop_flash() |