import tkinter as tk
import random
def show_warm_tip():
# 创建新的提示窗口(不关闭旧窗口,持续新增)
window = tk.Toplevel()
window.attributes('-topmost', False) # 不强制置顶(避免遮挡所有内容,可改为True强制置顶)
window.attributes('-alpha', 0.9) # 90%透明度,叠加时不刺眼
# 随机窗口位置(确保完全显示在屏幕内)
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
window_width = 250
window_height = 60
x = random.randrange(0, screen_width - window_width)
y = random.randrange(0, screen_height - window_height)
window.title('温馨提示')
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
# 随机提示文字
tips = [
'多喝水哦~', '保持微笑呀', '每天都要元气满满',
'记得吃水果', '保持好心情', '好好爱自己', '我想你了',
'梦想成真', '期待下一次见面', '金榜题名',
'顺顺利利', '早点休息', '愿所有烦恼都消失',
'别熬夜', '今天过得开心嘛', '天冷了,多穿衣服'
]
tip = random.choice(tips)
# 随机背景颜色
bg_colors = [
'lightpink', 'skyblue', 'lightgreen', 'lavender',
'lightyellow', 'plum', 'coral', 'bisque', 'aquamarine',
'mistyrose', 'honeydew', 'lavenderblush', 'oldlace'
]
bg = random.choice(bg_colors)
# 创建并显示标签
label = tk.Label(
window,
text=tip,
bg=bg,
font=('微软雅黑', 16),
width=30,
height=3,
justify=tk.CENTER
)
label.pack()
# 每隔1秒弹出一个新窗口(可调整间隔时间,单位毫秒)
window.after(10, show_warm_tip)
if __name__ == "__main__":
# 主窗口(隐藏)
root = tk.Tk()
root.withdraw()
# 启动第一个提示窗口,之后每秒新增一个
show_warm_tip()
# 保持程序运行(关闭所有窗口或按Ctrl+C停止)
root.mainloop()