56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import tkinter as tk
|
|
import random
|
|
import time
|
|
|
|
messages = [
|
|
'我想你了', '保持好心情', '梦想成真',
|
|
'早点休息', '今天过得开心嘛', '好想见到你',
|
|
'金榜题名', '多喝水哦~', '好好爱自己',
|
|
'记得吃水果', '顺顺利利', '期待下一次见面',
|
|
'午饭要吃热乎的', '你超棒的!', '保持微笑呀',
|
|
'别熬夜', '你已经做得很好啦', '天冷,多穿衣服',
|
|
'愿今晚有个好梦', '我爱你,老妈'
|
|
]
|
|
|
|
def get_random_color():
|
|
colors = ['pink', 'lightblue', 'lightgreen', 'lightyellow',
|
|
'lavender', 'mistyrose', 'paleturquoise', 'peachpuff'
|
|
]
|
|
return random.choice(colors)
|
|
|
|
def create_float_windows(root):
|
|
window = tk.Toplevel(root)
|
|
|
|
width = root.winfo_screenwidth()
|
|
height = root.winfo_screenheight()
|
|
|
|
x = random.randrange(0, width - 200)
|
|
y = random.randrange(0, height - 100)
|
|
window.geometry(f"+{x}+{y}")
|
|
|
|
message = random.choice(messages)
|
|
color = get_random_color()
|
|
|
|
tk.Label(window,
|
|
text=message,
|
|
bg=color,
|
|
font=('楷体',18),
|
|
width=15,
|
|
height=2).pack()
|
|
|
|
def create_windows_periodically(root, count=100, delay=50):
|
|
if count > 0:
|
|
create_float_windows(root)
|
|
|
|
root.after(delay, create_windows_periodically, root, count - 1, delay)
|
|
|
|
else:
|
|
root.after(5000, root.quit)
|
|
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
root.withdraw()
|
|
|
|
create_windows_periodically(root, 200, 70)
|
|
|
|
root.mainloop() |