本文最后更新于216 天前,其中的信息可能已经过时,如有错误请发送邮件到big_fw@foxmail.com
源码
import random
import tkinter as tk
from tkinter import Toplevel, Label, Button
def show_warm_tip(tip: str) -> None:
window = Toplevel()
window.title("温馨提示")
bg_colors: list[str] = [
"lightpink", "skyblue", "lightgreen", "lavender",
"lightyellow", "plum", "coral", "bisque", "aquamarine",
"mistyrose", "honeydew", "lavenderblush", "oldlace"
]
bg: str = random.choice(bg_colors)
Label(
window,
text=tip,
bg=bg,
font=("微软雅黑", 16),
width=30,
height=3
).pack(pady=10)
Button(
window,
text="好的",
command=window.destroy,
font=("微软雅黑", 12)
).pack(pady=5)
x: int = random.randint(25, 2000)
y: int = random.randint(25, 1000)
window.geometry(f"+{x}+{y}")
def schedule_popups(tips: list[str], interval: int = 100, count: int = 10) -> None:
if count > 0:
tip_text: str = random.choice(tips)
show_warm_tip(tip_text)
_ = root.after(interval, schedule_popups, tips, interval, count - 1) # type: ignore
def main() -> None:
global root
root = tk.Tk()
root.withdraw()
tips: list[str] = [
"请注意休息!",
"多喝水哦~",
"记得活动一下!",
"保护眼睛很重要!",
"工作辛苦了!",
"保持好心情!",
"注意坐姿!",
"记得保存工作!"
]
schedule_popups(tips, interval=50, count=100)
root.mainloop()
if __name__ == "__main__":
main()
打包好的文件下载连接https://www.123865.com/s/dy0yVv-8ijwd

