import tkinter as tk import random import threading import time import math def heart_x(t, size=10): """计算爱心形状的x坐标""" return size * 16 * (math.sin(t) ** 3) def heart_y(t, size=10): """计算爱心形状的y坐标""" return -size * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)) def show_warm_tip(x, y, delay=0, is_scatter=False): """在指定位置显示温馨提醒窗口""" if delay > 0: time.sleep(delay) # 创建窗口 window = tk.Tk() # 设置窗口标题和大小 window.title('温馨提示') window_width = 150 # 减小窗口宽度 window_height = 40 # 减小窗口高度 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) # 创建标签并显示文字 tk.Label( window, text=tip, bg=bg, font=('微软雅黑', 12), # 字体调小 width=20, height=2 ).pack() # 窗口置顶显示 window.attributes('-topmost', True) # 如果是铺散效果,添加动画 if is_scatter: def animate_window(): start_time = time.time() duration = 1.5 # 动画持续时间 start_x = x start_y = y # 随机方向 angle = random.uniform(0, 2 * math.pi) distance = random.uniform(100, 300) # 移动距离 end_x = start_x + distance * math.cos(angle) end_y = start_y + distance * math.sin(angle) # 确保不超出屏幕 end_x = max(0, min(screen_width - window_width, end_x)) end_y = max(0, min(screen_height - window_height, end_y)) while True: elapsed = time.time() - start_time if elapsed > duration: window.geometry(f"{window_width}x{window_height}+{int(end_x)}+{int(end_y)}") break # 缓动函数,先快后慢 progress = elapsed / duration ease_progress = 1 - (1 - progress) ** 2 current_x = start_x + (end_x - start_x) * ease_progress current_y = start_y + (end_y - start_y) * ease_progress window.geometry(f"{window_width}x{window_height}+{int(current_x)}+{int(current_y)}") window.update() time.sleep(0.016) # 约60fps # 在新线程中运行动画 anim_thread = threading.Thread(target=animate_window) anim_thread.daemon = True anim_thread.start() window.mainloop() # 获取屏幕尺寸 root = tk.Tk() screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() root.destroy() # 只计算爱心轮廓的点,不填充内部 heart_points = [] for i in range(0, 628, 8): # 步长适中 t = i / 100 x = heart_x(t, 15) # 增大缩放因子,使爱心更大 y = heart_y(t, 15) heart_points.append((x, y)) # 限制窗口数量,只使用轮廓点 max_windows = len(heart_points) # 使用所有轮廓点 # 创建线程列表 threads = [] # 创建窗口线程,按顺序显示爱心轮廓 for i in range(max_windows): x, y = heart_points[i] # 将坐标转换为屏幕坐标(爱心居中显示) screen_x = int(screen_width / 2 + x) screen_y = int(screen_height / 2 + y) # 计算延迟时间 - 最后10%的窗口速度变慢 if i < max_windows * 0.9: # 前90%的窗口使用正常速度 delay = i * 0.1 thread_delay = 0.01 # 线程启动间隔 else: # 最后10%的窗口速度变慢 progress = (i - max_windows * 0.9) / (max_windows * 0.1) # 计算在最后10%中的进度 delay = i * 0.1 + progress * 2.0 # 增加额外的延迟 thread_delay = 0.05 # 增加线程启动间隔 # 创建线程 t = threading.Thread(target=show_warm_tip, args=(screen_x, screen_y, delay, False)) threads.append(t) t.start() time.sleep(thread_delay) # 线程启动间隔 # 等待爱心显示完成 time.sleep(max_windows * 0.1 + 2.0 + 1) # 等待爱心动画完成 # 创建铺散开的窗口 scatter_windows = 6 # 铺散开的窗口数量 scatter_threads = [] for i in range(scatter_windows): # 随机在爱心中心附近生成起始位置 center_x = screen_width / 2 center_y = screen_height / 2 start_x = center_x + random.uniform(-50, 50) start_y = center_y + random.uniform(-50, 50) # 创建铺散窗口线程 t = threading.Thread(target=show_warm_tip, args=(start_x, start_y, 0, True)) scatter_threads.append(t) t.start() time.sleep(0.2) # 铺散窗口启动间隔 # 等待所有线程完成 for t in threads: t.join() for t in scatter_threads: t.join()