返回列表 发布新帖

花哨桌面 V 4.0.0 (最终版)

2849 0
邓小K 发表于 昨天 00:03 | 查看全部 阅读模式 <

马上注册,结交更多好友,享用更多功能,让你轻松玩转小K网。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
花哨桌面  经过几个版本的迭代 这个版本将是最后的版本,修复了之前群友们提出的一些问题.同时增加了一些优化
1.新增了托盘功能
退出
切换主题
启动开机启动
启动背景替换
设置图片大小
2.完善了更多主题,可选择,总有一款你喜欢的吧.........
灌篮高手
海贼王
火影忍者
马里奥
哪吒
七龙珠
犬夜叉
默认(宫崎骏风格)

3.摸鱼背景小游戏分数统计
4.自定义主题,大家可以根据自己喜好,在程序下面创建自己的资源,按照格式增加自己的主题风格,自己拓展
5.目前是win10系统开发的 win不兼容,会一点点编程的用源码自己编译改造下哦,随后源码奉上
6.程序也就是学习中突发灵感随手做的项目,大家勿喷哦,就是个娱乐的小玩意
7.软件也就不更新了,搞别的玩去了

下载链接
通过网盘分享的文件:花哨桌面(最终版本).rar
链接: https://pan.baidu.com/s/1YnVzRQE9YOAUoT5bg8VpoA?pwd=tnrj 提取码: tnrj

主题:

花哨桌面 V 4.0.0 (最终版)

花哨桌面 V 4.0.0 (最终版)

                               
登录/注册后可看大图


源码:
  1. import ctypes
  2. import os
  3. import random
  4. import sys
  5. import time
  6. import configparser

  7. import winshell
  8. from PyQt5.QtCore import Qt, QTimer, QPoint
  9. from PyQt5.QtGui import QPainter, QColor, QPixmap, QCursor, QFont, QIcon
  10. from PyQt5.QtWidgets import QApplication, QWidget, QSystemTrayIcon, QMenu, QAction, QInputDialog, QMessageBox
  11. from PyQt5.QtGui import QMovie
  12. from PyQt5.QtWidgets import QLabel

  13. influence_range = 30  # 鼠标影响范围
  14. QPixmap_size = 150 # 图标大小范围


  15. # 开机自动启动实现
  16. def add_to_startup():
  17.     """通过创建启动项实现开机自动启动"""
  18.     try:
  19.         import winshell
  20.         from win32com.client import Dispatch
  21.     except ImportError:
  22.         print("请安装依赖库:pip install pywin32 winshell")
  23.         return

  24.     startup_folder = winshell.startup()  # 获取启动目录
  25.     print("添加到启动项:", startup_folder)
  26.     shortcut_path = os.path.join(startup_folder, "花哨桌面.lnk")
  27.     if not os.path.exists(shortcut_path):
  28.         shell = Dispatch('WScript.Shell')
  29.         shortcut = shell.CreateShortCut(shortcut_path)
  30.         # 判断是否是打包后的exe环境
  31.         if getattr(sys, 'frozen', False):
  32.             # 打包后的exe路径
  33.             executable_path = sys.executable
  34.         else:
  35.             # 开发环境,使用当前脚本路径
  36.             executable_path = os.path.abspath(__file__)
  37.         # 快捷方式直接指向 .exe 文件,无需额外参数
  38.         shortcut.Targetpath = executable_path
  39.         shortcut.Arguments = ''  # 因为目标已经是exe,不需要参数
  40.         shortcut.WorkingDirectory = os.path.dirname(executable_path)  # 设置工作目录为exe所在目录
  41.         shortcut.save()
  42.         print("已添加到开机启动项")
  43.     else:
  44.         print("已存在开机启动项")


  45. # 获取桌面窗口句柄并嵌入
  46. def get_desktop_window():
  47.     # 查找ProgMan窗口
  48.     progman = ctypes.windll.user32.FindWindowW('ProgMan', None)
  49.     # 发送0x052C消息生成WorkerW窗口
  50.     ctypes.windll.user32.SendMessageW(progman, 0x052C, 0, 0)
  51.     hwnd = ctypes.windll.user32.FindWindowExW(None, None, 'WorkerW', None)
  52.     while hwnd:
  53.         # 查找包含SHELLDLL_DefView的子窗口
  54.         shell_view = ctypes.windll.user32.FindWindowExW(hwnd, None, 'SHELLDLL_DefView', None)
  55.         if shell_view:
  56.             return hwnd
  57.         hwnd = ctypes.windll.user32.FindWindowExW(None, hwnd, 'WorkerW', None)
  58.     return None


  59. def get_resource_path(relative_path):
  60.     """获取资源文件的路径,支持开发环境和打包后的 exe 环境"""
  61.     base_path = os.path.abspath(".")
  62.     # 判断是否是打包后的exe环境
  63.     if getattr(sys, 'frozen', False):
  64.         # 打包后的exe路径
  65.         base_path = sys.executable
  66.     else:
  67.         # 开发环境,使用当前脚本路径
  68.         base_path = os.path.abspath(__file__)
  69.     return os.path.join(os.path.dirname(base_path) , relative_path)


  70. def get_base_path():
  71.     """获取资源文件的基础路径"""
  72.     return get_resource_path("")


  73. class Snowflake:
  74.     def __init__(self, max_width, max_height, image_paths):
  75.         self.x = random.randint(0, max_width)
  76.         self.y = random.randint(-max_height, 0)  # 从屏幕上方随机位置生成
  77.         self.vx = random.uniform(-1, 1)
  78.         self.vy = random.uniform(0.5, 1.5)  # 向下飘落的速度
  79.         self.radius = random.randint(5, 10)
  80.         self.color = QColor(255, 255, 255, 200)
  81.         # 随机加载素材目录下的图片
  82.         image_path = random.choice(image_paths)
  83.         self.image_name = os.path.basename(image_path)  # 获取图片名称
  84.         self.pixmap = QPixmap(image_path)
  85.         self.pixmap = self.pixmap.scaled(self.radius * 3, self.radius * 3, Qt.KeepAspectRatio, Qt.SmoothTransformation)

  86.     def move(self, max_width, max_height, mouse_pos=None, speed_increment=0):
  87.         # 如果有鼠标位置信息,检测是否需要弹开
  88.         if mouse_pos:
  89.             mouse_x, mouse_y = mouse_pos
  90.             distance = ((self.x - mouse_x) ** 2 + (self.y - mouse_y) ** 2) ** 0.5
  91.             if distance < influence_range:  # 增大鼠标影响范围阈值
  92.                 self.vx = (self.x - mouse_x) * 0.2  # 增强弹开力度
  93.                 self.vy = -(self.y - mouse_y) * 0.2  # 增强弹开力度
  94.                 self.x += self.vx * 3  # 增强弹开力度
  95.                 self.y += self.vy * 3  # 增强弹开力度
  96.             else:
  97.                 self.x += self.vx
  98.                 self.y += self.vy + speed_increment  # 动态调整速度
  99.         else:
  100.             self.x += self.vx
  101.             self.y += self.vy + speed_increment  # 动态调整速度

  102.         # 判断是否到达地面或逃出边界
  103.         if self.y >= max_height or self.x < 0 or self.x > max_width:
  104.             return False  # 需要销毁
  105.         return True  # 继续存在

  106.     def draw(self, painter):
  107.         # 使用图片绘制
  108.         # 将 self.x 和 self.y 转换为整数类型
  109.         painter.drawPixmap(QPoint(int(self.x - self.radius), int(self.y - self.radius)), self.pixmap)


  110. class DynamicWallpaper(QWidget):
  111.     def __init__(self):
  112.         super().__init__()
  113.         self.base_path = get_base_path()  # 获取基础路径
  114.         self.config_path = get_resource_path("花哨.ini")
  115.         self.config = configparser.ConfigParser()
  116.         self.config.read(self.config_path)

  117.         # 初始化主题相关变量
  118.         self.current_theme = self.config.get("Settings", "Theme", fallback="默认主题")
  119.         self.themes = self.load_themes()
  120.         self.load_theme(self.current_theme)

  121.         # 初始化开机启动状态
  122.         self.startup_enabled = self.config.getboolean("Settings", "Startup", fallback=False)

  123.         # 新增:初始化桌面背景修改状态
  124.         self.modify_background_enabled = self.config.getboolean("Settings", "ModifyBackground", fallback=True)

  125.         # 初始化系统托盘
  126.         self.tray_icon = QSystemTrayIcon(self)
  127.         self.init_tray_icon()

  128.         # 初始化扫把图片列表
  129.         self.broom_pixmap_list = self.load_broom_pixmaps()
  130.         self.current_boomGif = QMovie(os.path.join(self.theme_dir, "boom.gif"))
  131.         self.current_boom = 0
  132.         self.current_broom_index = 0
  133.         self.collision_count = 0
  134.         self.collision_max = 0
  135.         self.image_name = None
  136.         self.broom_effect_duration = QPixmap_size
  137.         self.last_collision_time = 0

  138.         # 初始化窗口属性
  139.         self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowTransparentForInput)
  140.         self.setAttribute(Qt.WA_TranslucentBackground)
  141.         self.setGeometry(0, 0, QApplication.desktop().screenGeometry().width(),
  142.                          QApplication.desktop().screenGeometry().height())

  143.         # 初始化gif窗口属性
  144.         self.gif_label = QLabel(self)
  145.         self.gif_label.setScaledContents(True)
  146.         self.gif_label.hide()

  147.         # 创建元素
  148.         self.snowflakes = set()
  149.         for _ in range(50):
  150.             self.snowflakes.add(Snowflake(self.width(), self.height(), self.snowflake_image_paths))

  151.         # 定时器更新动画
  152.         self.timer = QTimer(self)
  153.         self.timer.timeout.connect(self.update_snowflakes)
  154.         self.timer.start(30)

  155.         # 嵌入到桌面窗口
  156.         desktop_hwnd = get_desktop_window()
  157.         if desktop_hwnd:
  158.             self.winId()
  159.             ctypes.windll.user32.SetParent(int(self.windowHandle().winId()), desktop_hwnd)

  160.         self.mouse_pos = None

  161.         # 初始化配置项
  162.         self.influence_range = self.config.getint("Settings", "InfluenceRange", fallback=30)
  163.         self.QPixmap_size = self.config.getint("Settings", "QPixmapSize", fallback=150)

  164.     def load_broom_pixmaps(self):
  165.         """加载扫把图片"""
  166.         broom_dir = get_resource_path(os.path.join("花哨桌面", self.current_theme, "头像"))
  167.         if not os.path.exists(broom_dir):
  168.             raise FileNotFoundError(f"头像目录不存在: {broom_dir}")
  169.         return [
  170.             QPixmap(os.path.join(broom_dir, f)).scaled(QPixmap_size, QPixmap_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
  171.             for f in random.sample(
  172.                 [f for f in os.listdir(broom_dir) if f.endswith(".png")],
  173.                 k=len([f for f in os.listdir(broom_dir) if f.endswith(".png")])
  174.             )
  175.         ]

  176.     def load_themes(self):
  177.         """加载所有主题"""
  178.         themes_dir = get_resource_path("花哨桌面")
  179.         if not os.path.exists(themes_dir) or not os.path.isdir(themes_dir):
  180.             raise FileNotFoundError(f"主题目录不存在或路径无效: {themes_dir}")
  181.         return [d for d in os.listdir(themes_dir) if os.path.isdir(os.path.join(themes_dir, d))]

  182.     def load_theme(self, theme_name):
  183.         """加载指定主题"""
  184.         self.theme_dir = os.path.join(self.base_path, "花哨桌面", theme_name)
  185.         self.current_theme = theme_name

  186.         # 加载头像和素材
  187.         self.broom_pixmap_list = self.load_broom_pixmaps()

  188.         # 加载素材目录下的图片
  189.         self.snowflake_image_paths = [
  190.             os.path.join(self.theme_dir, "素材", f)
  191.             for f in os.listdir(os.path.join(self.theme_dir, "素材"))
  192.             if f.endswith(".png")
  193.         ]

  194.         # 新增:根据配置文件决定是否修改桌面背景
  195.         if self.config.getboolean("Settings", "ModifyBackground", fallback=True):
  196.             # 加载 back 文件夹中的图片文件并设置为桌面背景
  197.             back_dir = os.path.join(self.theme_dir, "back")
  198.             if os.path.exists(back_dir):
  199.                 back_files = [f for f in os.listdir(back_dir) if f.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp'))]
  200.                 if back_files:
  201.                     back_image_path = os.path.join(back_dir, back_files[0])
  202.                     self.set_desktop_background(back_image_path)

  203.         # 加载 boom.gif
  204.         self.current_boomGif = QMovie(os.path.join(self.theme_dir, "boom.gif"))
  205.         self.current_boomGif.start()

  206.         # 重新生成雪花元素
  207.         self.snowflakes = set()
  208.         for _ in range(50):
  209.             self.snowflakes.add(Snowflake(self.width(), self.height(), self.snowflake_image_paths))

  210.     def set_desktop_background(self, image_path):
  211.         """使用 Windows API 设置桌面背景"""
  212.         SPI_SETDESKWALLPAPER = 20
  213.         ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, image_path, 3)

  214.     def init_tray_icon(self):
  215.         """初始化系统托盘"""
  216.         self.tray_icon.setIcon(QIcon(QPixmap("花哨.png")))  # 设置托盘图标
  217.         self.tray_icon.setToolTip("花哨桌面")

  218.         # 创建托盘菜单
  219.         menu = QMenu()

  220.         # 主题切换菜单
  221.         theme_menu = QMenu("切换主题", self)
  222.         for theme in self.themes:
  223.             action = QAction(theme, self)
  224.             action.triggered.connect(lambda _, t=theme: self.switch_theme(t))
  225.             # 如果当前主题与菜单项一致,在名称前添加选中标记
  226.             if theme == self.current_theme:
  227.                 action.setText(f"{theme} &#10003;")
  228.             theme_menu.addAction(action)
  229.         menu.addMenu(theme_menu)

  230.         # 开机启动开关
  231.         self.startup_action = QAction("启用开机启动", self, checkable=True)
  232.         self.startup_action.setChecked(self.startup_enabled)  # 使用配置文件中的值
  233.         self.startup_action.triggered.connect(self.toggle_startup)
  234.         menu.addAction(self.startup_action)

  235.         # 新增:桌面背景修改开关
  236.         self.modify_background_action = QAction("启用桌面背景修改", self, checkable=True)
  237.         self.modify_background_action.setChecked(self.config.getboolean("Settings", "ModifyBackground", fallback=True))
  238.         self.modify_background_action.triggered.connect(self.toggle_modify_background)
  239.         menu.addAction(self.modify_background_action)

  240.         # 添加鼠标影响范围设置
  241.         influence_range_action = QAction("设置鼠标影响范围", self)
  242.         influence_range_action.triggered.connect(self.set_influence_range)
  243.         menu.addAction(influence_range_action)

  244.         # 添加图标大小设置
  245.         pixmap_size_action = QAction("设置图标大小", self)
  246.         pixmap_size_action.triggered.connect(self.set_QPixmap_size)
  247.         menu.addAction(pixmap_size_action)

  248.         exit_action = QAction("退出", self)
  249.         exit_action.triggered.connect(self.close)
  250.         menu.addAction(exit_action)

  251.         self.tray_icon.setContextMenu(menu)
  252.         self.tray_icon.show()

  253.     def switch_theme(self, theme_name):
  254.         """切换主题"""
  255.         self.load_theme(theme_name)
  256.         self.update()
  257.         self.update_tray_menu()
  258.         # 保存当前主题到配置文件
  259.         self.save_config()

  260.     def update_tray_menu(self):
  261.         """更新托盘菜单内容"""
  262.         menu = self.tray_icon.contextMenu()
  263.         menu.clear()

  264.         # 主题切换菜单
  265.         theme_menu = QMenu("切换主题", self)
  266.         for theme in self.themes:
  267.             action = QAction(theme, self)
  268.             action.triggered.connect(lambda _, t=theme: self.switch_theme(t))
  269.             # 如果当前主题与菜单项一致,在名称前添加选中标记
  270.             if theme == self.current_theme:
  271.                 action.setText(f"{theme} &#10003;")
  272.             theme_menu.addAction(action)
  273.         menu.addMenu(theme_menu)

  274.         # 开机启动开关
  275.         self.startup_action = QAction("启用开机启动", self, checkable=True)
  276.         self.startup_action.setChecked(os.path.exists(os.path.join(winshell.startup(), "花哨桌面.lnk")))
  277.         self.startup_action.triggered.connect(self.toggle_startup)
  278.         menu.addAction(self.startup_action)

  279.         # 新增:桌面背景修改开关
  280.         self.modify_background_action = QAction("启用桌面背景修改", self, checkable=True)
  281.         self.modify_background_action.setChecked(self.config.getboolean("Settings", "ModifyBackground", fallback=True))
  282.         self.modify_background_action.triggered.connect(self.toggle_modify_background)
  283.         menu.addAction(self.modify_background_action)

  284.         # 添加鼠标影响范围设置
  285.         influence_range_action = QAction("设置鼠标影响范围", self)
  286.         influence_range_action.triggered.connect(self.set_influence_range)
  287.         menu.addAction(influence_range_action)

  288.         # 添加图标大小设置
  289.         pixmap_size_action = QAction("设置图标大小", self)
  290.         pixmap_size_action.triggered.connect(self.set_QPixmap_size)
  291.         menu.addAction(pixmap_size_action)

  292.         exit_action = QAction("退出", self)
  293.         exit_action.triggered.connect(self.close)
  294.         menu.addAction(exit_action)

  295.     def toggle_startup(self):
  296.         """启用/禁用开机启动"""
  297.         self.startup_enabled = not self.startup_enabled
  298.         self.update_startup_status()
  299.         # 保存开机启动状态到配置文件
  300.         self.save_config()

  301.     def update_startup_status(self):
  302.         """更新开机启动状态"""
  303.         if self.startup_enabled:
  304.             add_to_startup()
  305.         else:
  306.             startup_folder = winshell.startup()
  307.             shortcut_path = os.path.join(startup_folder, "花哨桌面.lnk")
  308.             if os.path.exists(shortcut_path):
  309.                 os.remove(shortcut_path)

  310.     def toggle_modify_background(self):
  311.         """启用/禁用桌面背景修改"""
  312.         self.modify_background_enabled = not self.modify_background_enabled
  313.         self.update_modify_background_status()
  314.         # 保存桌面背景修改状态到配置文件
  315.         self.save_config()

  316.     def update_modify_background_status(self):
  317.         """更新桌面背景修改状态"""
  318.         if self.modify_background_enabled:
  319.             self.load_theme(self.current_theme)  # 重新加载主题以应用背景修改
  320.         else:
  321.             # 恢复默认桌面背景
  322.             SPI_SETDESKWALLPAPER = 20
  323.             ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, "", 3)

  324.     def set_influence_range(self):
  325.         """设置鼠标影响范围"""
  326.         new_value, ok = QInputDialog.getInt(self, "设置鼠标影响范围", "请输入新的鼠标影响范围值:", self.influence_range, 20, 50)
  327.         if ok:
  328.             self.influence_range = new_value
  329.             self.save_config()
  330.             QMessageBox.information(self, "成功", f"鼠标影响范围已设置为 {new_value}")

  331.     def set_QPixmap_size(self):
  332.         """设置图标大小"""
  333.         new_value, ok = QInputDialog.getInt(self, "设置图标大小", "请输入新的图标大小值:", self.QPixmap_size, 50, 200)
  334.         if ok:
  335.             self.QPixmap_size = new_value
  336.             self.save_config()
  337.             QMessageBox.information(self, "成功", f"图标大小已设置为 {new_value}")

  338.     def save_config(self):
  339.         """保存配置到花哨.ini"""
  340.         if not self.config.has_section("Settings"):
  341.             self.config.add_section("Settings")
  342.         self.config.set("Settings", "Theme", self.current_theme)
  343.         self.config.set("Settings", "Startup", str(self.startup_enabled))
  344.         self.config.set("Settings", "ModifyBackground", str(self.modify_background_enabled))  # 新增配置项
  345.         self.config.set("Settings", "InfluenceRange", str(self.influence_range))
  346.         self.config.set("Settings", "QPixmapSize", str(self.QPixmap_size))
  347.         with open(self.config_path, "w") as config_file:
  348.             self.config.write(config_file)

  349.     def play_gif_at_position(self, position):
  350.         self.gif_label.setMovie(self.current_boomGif)
  351.         self.gif_label.resize(QPixmap_size, QPixmap_size)  # 设置大小
  352.         self.gif_label.move(position.x(), position.y())  # 移动到指定位置
  353.         self.current_boomGif.start()
  354.         self.gif_label.show()
  355.         # 设置定时器,在 2 秒后隐藏和停止动画
  356.         QTimer.singleShot(1000, lambda: self.stop_gif(self.current_boomGif))

  357.     def stop_gif(self, movie):
  358.         movie.stop()
  359.         self.gif_label.hide()

  360.     def update_snowflakes(self):
  361.         # 根据 collision_count 计算速度增量
  362.         speed_increment = (self.collision_count // 10) * 0.5  # 每增加 10,速度增加 0.1
  363.         # speed_increment = (self.collision_count // 1) * 1
  364.         for flake in list(self.snowflakes):  # 使用 list 复制集合以避免修改时迭代
  365.             if not flake.move(self.width(), self.height(), self.mouse_pos, speed_increment):  # 如果需要销毁
  366.                 self.snowflakes.remove(flake)  # 移除
  367.                 self.snowflakes.add(
  368.                     Snowflake(self.width(), self.height(), self.snowflake_image_paths))  # 在顶部生成新的,传递 image_paths 参数
  369.         self.update()  # 触发重绘

  370.     def get_current_time(self):
  371.         return int(time.time() * 1000)  # 毫秒级时间戳

  372.     def paintEvent(self, event):
  373.         painter = QPainter(self)
  374.         painter.setRenderHint(QPainter.Antialiasing)
  375.         # 获取鼠标当前位置
  376.         mouse_pos = QCursor.pos()
  377.         mouse_pos = self.mapFromGlobal(mouse_pos)
  378.         current_broom = self.broom_pixmap_list[self.current_broom_index]
  379.         # 绘制扫把
  380.         if self.current_boom == 0:
  381.             painter.drawPixmap(
  382.                 mouse_pos.x() - current_broom.width() // 2 + 40,
  383.                 mouse_pos.y() + 20,
  384.                 current_broom
  385.             )
  386.         else:
  387.             self.play_gif_at_position(mouse_pos)

  388.         # 绘制元素
  389.         for flake in self.snowflakes:
  390.             # 计算距离
  391.             distance = ((flake.x - mouse_pos.x()) ** 2 + (flake.y - mouse_pos.y()) ** 2) ** 0.5
  392.             if distance < influence_range:  # 鼠标影响范围阈值
  393.                 current_time = self.get_current_time()
  394.                 flake.vx = (flake.x - mouse_pos.x()) * 0.2
  395.                 flake.vy = -(flake.y - mouse_pos.y()) * 0.2
  396.                 flake.x += flake.vx * 3
  397.                 flake.y += flake.vy * 3
  398.                 flake.color.setAlpha(255)
  399.                 self.current_broom_index = (self.current_broom_index + 1) % len(self.broom_pixmap_list)
  400.                 # 基于素材记录碰撞逻辑
  401.                 if current_time - self.last_collision_time > self.broom_effect_duration:
  402.                     name = flake.image_name
  403.                     # print(f"当前素材名称:{name}")  # 打印图片名称
  404.                     self.last_collision_time = current_time
  405.                     if "炸弹.png" == name:
  406.                         self.current_boom = 1
  407.                         self.collision_count = 0
  408.                     else:
  409.                         self.current_boom = 0
  410.                         if self.image_name == name:
  411.                             self.collision_count += 1
  412.                             if self.collision_count > self.collision_max:
  413.                                 self.collision_max = self.collision_count
  414.                         else:
  415.                             self.image_name = name  # 更新上次碰撞的素材标识
  416.                             self.collision_count = 1

  417.                 self.update()
  418.             else:
  419.                 flake.color.setAlpha(200)  # 其他时刻保持正常透明度
  420.             # 绘制元素
  421.             flake.draw(painter)
  422.         # 绘制鼠标影响范围的浅浅背景色为圆形
  423.         painter.setPen(Qt.NoPen)  # 不绘制边框
  424.         painter.setBrush(QColor(255, 255, 255, 50))  # 半透明白色背景

  425.         painter.drawEllipse(
  426.             mouse_pos.x() - influence_range,
  427.             mouse_pos.y() - influence_range,
  428.             influence_range * 2,
  429.             influence_range * 2
  430.         )

  431.         # 在窗体中央绘制碰撞次数
  432.         painter.setPen(QColor(255, 255, 255, 200))  # 透明白色
  433.         painter.setFont(QFont("Arial", 15))
  434.         text = f"max: {self.collision_max}  speed: {self.collision_count // 10} count: {self.collision_count}"
  435.         text_rect = painter.boundingRect(self.rect(), Qt.AlignCenter, text)
  436.         painter.drawText(text_rect, Qt.AlignCenter, text)

  437.     # 捕获鼠标移动事件
  438.     def mouseMoveEvent(self, event):
  439.         self.mouse_pos = (event.x(), event.y())


  440. if __name__ == '__main__':
  441.     add_to_startup()
  442.     mutex = ctypes.windll.kernel32.CreateMutexW(None, True, "Local/SnowfallProgramMutex")
  443.     if ctypes.windll.kernel32.GetLastError() == 0x00000010:
  444.         print("检测到程序已在运行,即将退出...")
  445.         sys.exit(-1)
  446.     app = QApplication(sys.argv)
  447.     w = DynamicWallpaper()
  448.     w.show()
  449.     sys.exit(app.exec_())
复制代码


请大家文明发帖,遵守法律法规!站长QQ460551

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表