1

I have made an application in Python 3.6 which built up on differet components. In the app I use TrayIcon.

It works fantastically but when I compile it by the Python compiler, the problem occured when I build it to an *.exe by CX_Freeze. The app works fantastic after the *.exe is built, but the tray icon does not show up at the built *.exe.

I think I missed something. It looks like I have all of the required depends, and it builds the *.exe without errors, but I have no idea why the TrayIcon doesn't want to show up.

Please, help me to fix this error. Thanks.

To Simons Comment: Here is my setup script: Yes, i am new to python it is such an awesome language, i'm learning so much, and i will take good advices :)

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)
Nikolaj
  • 11
  • 3

0 Answers0