当前位置: 首页> 财经> 金融 > 公司网站开发方案_银川seo优化_网站seo优化是什么_企业网站设计思路

公司网站开发方案_银川seo优化_网站seo优化是什么_企业网站设计思路

时间:2025/7/11 7:33:41来源:https://blog.csdn.net/qq_31939617/article/details/145696714 浏览次数:0次
公司网站开发方案_银川seo优化_网站seo优化是什么_企业网站设计思路

Python .py文件打包成.exe可执行程序,带托盘图标的可执行文件

安装pyinstalle

查看是否安装了pyinstaller
已安装

C:\Users\Administrator>pip show pyinstaller
Name: pyinstaller
Version: 6.12.0
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.
Home-page: https://www.pyinstaller.org/
Author: Hartmut Goebel, Giovanni Bajo, David Vierra, David Cortesi, Martin Zibricky
Author-email:
License: GPLv2-or-later with a special exception which allows to use PyInstaller to build and distribute non-free programs (including commercial ones)
Location: C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires: altgraph, packaging, pefile, pyinstaller-hooks-contrib, pywin32-ctypes, setuptools
Required-by:

未安装,则会收到类似于Could not find installation information for package 'pyinstaller’的提示信息
安装

打包

pip install pyinstaller

使用pyInstaller生成可执行文件,到需要生成文件的路径下,如果你的应用名为test.py,可执行下列命令:

pyinstaller --onefile test.py
pyinstaller --onefile --icon=A1.ico test.py
#--onefile选项表示将所有依赖打包进一个单独的可执行文件中。
#--icon带图标,不加就是默认的

打包完成后,会在dist目录下生成一个可执行文件
如果不需要托盘图标,就可以用了

托盘图标设置
让程序在右下角显示托盘图标,需要在程序中添加相应的代码。以PyQt5介绍如何设置托盘图标
导入

import sys
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QAction
from PyQt5.QtGui import QIcon

创建托盘图标

    app = QApplication(sys.argv)icon = QSystemTrayIcon(QIcon('A1.png'), app)icon.show()menu = QMenu(app)exit_action = QAction('Exit', app)exit_action.triggered.connect(app.quit)menu.addAction(exit_action)icon.setContextMenu(menu)sys.exit(app.exec_())

A1.png是你的托盘图标文件路径。这段代码会创建一个托盘图标,并添加一个退出菜单项。

在PyInstaller打包时添加托盘图标
在这里插入图片描述
重新运行pyinstaller A1.spec命令进行打包

常见问题解决方法

打包后的程序无法显示托盘图标

这可能是由于托盘图标文件没有正确打包进去导致的。请确保在spec文件中添加了正确的托盘图标文件路径。

打包后的程序在Windows 7下无法显示托盘图标

这可能是由于Windows 7系统对托盘图标的支持问题导致的。可以尝试使用其他托盘图标库,如pyqt5-trayicon

关键字:公司网站开发方案_银川seo优化_网站seo优化是什么_企业网站设计思路

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: