飘字代码
This commit is contained in:
parent
e229549c5b
commit
7a80291e54
53
main.py
Normal file
53
main.py
Normal file
@ -0,0 +1,53 @@
|
||||
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_periodicoally(root, count=100, delay=50):
|
||||
if count > 0:
|
||||
create_float_windows(root)
|
||||
|
||||
root.after(delay, create_windows_periodicoally, root, count - 1, delay)
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
|
||||
create_windows_periodicoally(root, 200, 70)
|
||||
|
||||
root.mainloop()
|
||||
Loading…
x
Reference in New Issue
Block a user