1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| import sys import random from PyQt5.QtWidgets import QApplication, QWidget, QLabel,QVBoxLayout from PyQt5.QtCore import QTimer, Qt from PyQt5.QtGui import QColor, QPalette
messages = [ "早安,开启美好一天!", "温暖的阳光洒满房间。", "愿你今天心情愉快。", "生活充满希望。", "微笑面对每一天。", "努力就有收获。", "幸福其实很简单。", "相信自己,勇敢前行。", "温柔以待世界。", "感受生活的美好。", "今天也要加油哦!", "阳光总在风雨后。", "遇见更好的自己。", "心怀感恩,快乐常在。", "愿你被世界温柔以待。", "梦想照进现实。", "每一天都是新的开始。", "保持热爱,奔赴山海。", "生活因你而美丽。", "愿你笑容常在。" ]
warm_colors = [ (255, 239, 213), (255, 228, 196), (255, 222, 173), (255, 182, 193), (255, 204, 153), (255, 250, 205), (255, 245, 238), (255, 228, 225), (255, 218, 185), (255, 160, 122), (255, 236, 139), (255, 215, 180), (255, 223, 211), (255, 240, 245), (255, 250, 240), (255, 239, 213), (255, 228, 181), (255, 192, 203), (255, 228, 225) ]
class Popup(QWidget): def __init__(self, message, color): super().__init__() self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Tool) self.setFixedSize(600, 200) self.setWindowTitle("温馨提示") label = QLabel(message, self) label.setStyleSheet("font-size: 50px; font-weight: bold; color: #333; font-family: 微软雅黑;") label.setAlignment(Qt.AlignCenter) layout = QVBoxLayout() layout.addWidget(label, alignment=Qt.AlignmentFlag.AlignCenter) self.setLayout(layout) palette = QPalette() palette.setColor(QPalette.Window, QColor(*color)) self.setPalette(palette) self.setAutoFillBackground(True)
class PopupGenerator: def __init__(self): self.count = 0 self.max_count = 50 self.timer = QTimer() self.timer.timeout.connect(self.show_popup) self.timer.start(100)
def show_popup(self): if self.count < self.max_count: msg = messages[self.count%messages.__len__()] color = warm_colors[self.count%warm_colors.__len__()] popup = Popup(msg, color) x = random.randint(100, 2000) y = random.randint(100, 1500) popup.move(x, y) popup.show() QApplication.instance().activePopups.append(popup) self.count += 1 else: self.timer.stop()
if __name__ == "__main__": app = QApplication(sys.argv) app.activePopups = [] generator = PopupGenerator() sys.exit(app.exec_())
|