Naposledy aktivní 5 days ago

gistfile1.txt Raw
1import tkinter as tk
2import random
3
4popup_count = 0
5TARGET_COUNT = 100
6
7
8def create_tip_window(main_root):
9 global popup_count
10 if popup_count >= TARGET_COUNT:
11 return
12
13 screen_w = main_root.winfo_screenwidth()
14 screen_h = main_root.winfo_screenheight()
15 base_win_w, base_win_h = 250, 60
16 final_win_w, final_win_h = base_win_w * 2, base_win_h * 2
17
18 if popup_count == TARGET_COUNT - 1:
19
20 x = (screen_w - final_win_w) // 2
21 y = (screen_h - final_win_h) // 2
22 win_w, win_h = final_win_w, final_win_h
23 tip_text = "我喜欢你"
24 bg_color = "lightpink"
25 font_style = ('微软雅黑', 24, 'bold')
26 border_width = 5
27 border_color = "#FF69B4"
28 else:
29
30 x = random.randint(0, screen_w - base_win_w)
31 y = random.randint(0, screen_h - base_win_h)
32 win_w, win_h = base_win_w, base_win_h
33 tips = [
34 '多喝水哦~', '保持微笑呀', '每天都要元气满满', '记得吃水果', '保持好心情',
35 '好好爱自己', '梦想成真', '期待下一次见面', '顺顺利利', '早点休息',
36 '愿所有烦恼都消失', '别熬夜', '今天过得开心嘛', '天冷了,多穿衣服', '照顾好自己', '我永远陪着你'
37 ]
38 bg_colors = [
39 'skyblue', 'lightgreen', 'lavender', 'lightyellow', 'plum',
40 'coral', 'bisque', 'aquamarine', 'mistyrose', 'honeydew'
41 ]
42 tip_text = random.choice(tips)
43 bg_color = random.choice(bg_colors)
44 font_style = ('微软雅黑', 14)
45 border_width = 0
46 border_color = "white"
47
48 tip_win = tk.Toplevel(main_root)
49 tip_win.title('温馨提示' if popup_count < TARGET_COUNT - 1 else 'Special Message')
50 tip_win.geometry(f"{win_w}x{win_h}+{x}+{y}")
51 tip_win.attributes('-topmost', True)
52 tip_win.attributes('-alpha', 0.85)
53 tip_win.config(borderwidth=border_width, relief="solid", bg=border_color)
54
55 label = tk.Label(
56 tip_win,
57 text=tip_text,
58 bg=bg_color,
59 font=font_style,
60 width=30 if popup_count == TARGET_COUNT - 1 else 20,
61 height=4 if popup_count == TARGET_COUNT - 1 else 2,
62 wraplength=final_win_w - 40 if popup_count == TARGET_COUNT - 1 else base_win_w - 20,
63 justify='center'
64 )
65 label.pack(padx=10, pady=10, fill='both', expand=True)
66
67 popup_count += 1
68
69
70def main():
71 root = tk.Tk()
72 root.withdraw()
73
74 def generate_loop():
75 create_tip_window(root)
76 if popup_count < TARGET_COUNT:
77 root.after(60, generate_loop)
78
79 generate_loop()
80
81 def on_main_close():
82 for child in root.winfo_children():
83 child.destroy()
84 root.destroy()
85
86 root.protocol("WM_DELETE_WINDOW", on_main_close)
87
88 root.mainloop()
89
90
91if __name__ == "__main__":
92 main()