我在Python 3.6
中创建了一个应用程序,它构建了不同的组件。在应用中,我使用了TrayIcon。
它非常有效,但是当我用Python编译器编译它时,当我通过*.exe
将它构建到CX_Freeze
时出现了问题。构建*.exe
后应用程序效果很棒,但托盘图标不会显示在构建的*.exe
上。
我想我错过了什么。看起来我已经拥有了所有必需的依赖项,它构建了*.exe
而没有错误,但我不知道为什么TrayIcon
不想显示。
请帮我修复此错误。感谢。
To Simons评论:这是我的设置脚本: 是的,我是python的新手,它是一种非常棒的语言,我学到了很多,我会采取很好的建议:)
import os, sys, datetime, uuid
from cx_Freeze import setup, Executable
from Lib import PAConfig
appConfig = PAConfig.PAConfig()
def genuuid():
return str(uuid.uuid4())
def yes_no(answer):
answer = answer + ' [y/n] ';
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
while True:
choice = input(answer).lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("Please respond with 'yes' or 'no'\n")
appVersion = input('Version? ->')
if eval(appVersion):
isbeta = yes_no('Is this a beta?')
if isbeta == False:
useEalierVersionUuid = input('Use previous upgrade code? Return for new version or type upgrade code');
os.environ['TCL_LIBRARY'] = 'c:/LOCAL_TO_PYTHON/PYTHON35-32/tcl/tcl8.6'
os.environ['TK_LIBRARY'] = 'c:/LOCAL_TO_PYTHON/PYTHON35-32/tcl/tk8.6'
appName = appConfig.getvalue('misc', 'AppTitle')
companyName = appConfig.getvalue('misc', 'CompanyName')
appUuid = 'printadapt-' + genuuid()
if isbeta == True:
appName = appName + ' Beta'
appUuid = 'ba24-printadapt-beta-e7429436-4b83-4d14'
if useEalierVersionUuid and isbeta == False:
appUuid = 'printadapt-' + useEalierVersionUuid
versionFilePath = 'version/' + appUuid + '.version'
if os.path.exists(versionFilePath):
f = open(versionFilePath, "r+")
else:
f = open(versionFilePath, "w", perms=0o644)
versionFile = open(versionFilePath,"a");
versionFile.write("\n-----------------------------------------------------\nVersion created: "+datetime.datetime.now().strftime("%d-%m-%Y %T")+" \nupgrade_code: ["+appUuid+"]\n-----------------------------------------------------\n")
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(
packages = ['win32api', 'win32con', 'win32gui_struct', 'winxpgui', 'win32gui', 'threading', 'queue', 'tkinter', 'datetime', 'time', 'sys', 'os', 'win32print', 'requests', 'itertools', 'glob', 'socket', 'json', 'webbrowser', 'traceback', 'logging', 'idna'],
excludes = [],
includes = ['Lib/PAConfig', 'Lib/PASocketClient', 'Lib/SysTrayIconModule'],
include_files=['Lib/', 'Lib/PAConfig.pyc', appConfig.getvalue('misc', 'AppIconPath'), '../tcl86t.dll', '../tk86t.dll']
)
base = 'Win32GUI' if sys.platform=='win32' else None
bdist_msi_options = {
'upgrade_code': '{' + appUuid + '}',
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % (companyName, appName)
}
#if 'bdist_msi' in sys.argv:
# sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + appName]
# sys.argv += ['--install-script', 'install.py']
executables = [
Executable(
script='main.py',
base=base,
targetName=appName + ".exe",
icon=appConfig.getvalue('misc', 'AppIconPath'),
copyright=appConfig.getvalue('misc', 'copyright'),
#shortcutName=appName,
#shortcutDir="MyProgramMenu",
)
#Executable('main.py', base=base, targetName=appName + ".exe", icon="printadapt.ico")
]
setup(name=appName,
scripts=['postinstall.py'],
version = appVersion,
description = appConfig.getvalue('misc', 'description'),
long_description = appConfig.getvalue('misc', 'long_description'),
author = appConfig.getvalue('misc', 'author'),
platforms=['Windows'],
#options = dict(build_exe = buildOptions),
#license='Apache License 2.0',
options = {'bdist_msi': bdist_msi_options, 'build_exe': buildOptions},
executables = executables)