我的快乐餐厅普通版
20.29 MB · 2025-12-18
运行程序后,你的屏幕上会不断弹出可爱的小窗口,内容如:
每个窗口:
tkinter、threading、time、randomimport tkinter as tk
import threading
import time
import random
# 温馨提示语列表(可自定义!)
tips = [
"*****要记得喝水哦(~ ̄▽ ̄)~",
"要多吃水果",
"天冷了多穿衣服",
"祝乔玉琼每天都有开心快乐",
"记得早睡9.·̫·̫?",
"祝*****梦想成真",
"要好好吃饭 {°•̀ω•́°}",
"一个人也要好好的(。・ω・。)",
"期待每一次见面 /// - ^ - ///",
"要多喝水啦~",
"要好好爱自己{3}~>ω<)",
"要加油哦~",
"万事如意",
]
# 背景色列表(使用十六进制颜色码)
colors = [
"#00BFFF", # 深天蓝
"#FF69B4", # 热粉红
"#32CD32", # 酸橙绿
"#87CEFA", # 亮天蓝
"#FFD700", # 金色
"#FFB6C1", # 浅粉红
"#98FB98", # 淡绿
"#BA55D3", # 中紫罗兰
"#FF6347", # 番茄红
"#00CED1", # 深青
]
def create_unclosable_tip():
"""创建一个无法关闭的弹窗"""
win = tk.Toplevel()
win.title("温馨提示")
# 随机位置(适配1920x1080屏幕)
x = random.randint(50, 1200)
y = random.randint(50, 700)
win.geometry(f"300x100+{x}+{y}")
# ⭐ 关键:彻底移除标题栏和关闭按钮(真正“无法关闭”)
win.overrideredirect(True)
# 随机背景色
bg_color = random.choice(colors)
win.configure(bg=bg_color)
# 显示温馨文字
label = tk.Label(
win,
text=random.choice(tips),
font=("微软雅黑", 13, "bold"),
bg=bg_color,
fg="white",
wraplength=250, # 自动换行
justify="center"
)
label.pack(expand=True, padx=10, pady=10)
def start_spawning():
"""持续创建弹窗(每0.5~2秒一个)"""
while True:
create_unclosable_tip()
time.sleep(random.uniform(0.5, 2.0)) # 随机间隔,避免卡顿
# 主程序入口
if __name__ == "__main__":
root = tk.Tk()
root.withdraw() # 隐藏主窗口(只显示弹窗)
# 启动弹窗线程(daemon=True:主程序退出时自动结束)
thread = threading.Thread(target=start_spawning, daemon=True)
thread.start()
root.mainloop()
效果展示:
保存代码:将上述代码保存为 love_popup.py
修改名字:将 tips 列表中的 “乔玉琼” 替换成你心仪之人的名字
运行程序
:
python love_popup.py
停止程序:按 Ctrl + C(命令行)或直接关闭终端(Windows 可能需任务管理器结束 python.exe)
pygame.mixer)plyer 库).exe 文件(用 PyInstaller)作者:花艺 日期:2025年10月29日 适用平台:Windows / macOS / Linux(需安装 Tkinter)