Reputation: 41
I'm trying to make a simple python GUI with tkiter. Recently I have a great trouble with tkinter Toplevel to set it's window icon. When I set a Toplevel's window icon at first it run's good on IDE or CMD then threre are no problem and when I convert it into EXE then there don't show the icon besides it there don't show other widget. At first tryed with cx_Freeze and as seeing the problem then I tryed it with pyinstaller and there are also same problem. I have alse tryed to solve it with internet but found nothing. The code is here .
from tkinter import *
from tkinter import Toplevel
from PIL import Image
def show():
window = Toplevel(root, bg= '#4e6c9a')
window.title('Ok')
window.tk.call('wm', 'iconbitmap', window._w, 'Key.ico')
bu = Button(window, text='me', command=window.destroy)
bu.pack()
root = Tk()
bt = Button(text = 'click', command=show)
bt.pack()
root.mainloop()
It run's well in IDE or with CMD. converting it to EXE with pyinstaller.... in console
pyinstaller -w -F --clean -n Removeer -i logo.ico main.py
78 INFO: PyInstaller: 4.1
78 INFO: Python: 3.8.7
78 INFO: Platform: Windows-7-6.1.7601-SP1
78 INFO: wrote F:\GUI\Removeer.spec
78 INFO: UPX is not available.
78 INFO: Removing temporary files and cleaning cache in C:\Users\IT Lab\AppData\Roaming\pyinstaller
93 INFO: Extending PYTHONPATH with paths
['F:\\GUI', 'F:\\GUI']
93 INFO: checking Analysis
93 INFO: Building Analysis because Analysis-00.toc is non existent
93 INFO: Initializing module dependency graph...
93 INFO: Caching module graph hooks...
109 INFO: Analyzing base_library.zip ...
2995 INFO: Processing pre-find module path hook distutils from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'
.
2995 INFO: distutils: retargeting to non-venv dir 'C:\\Python\\lib'
5803 INFO: Caching module dependency graph...
5943 INFO: running Analysis Analysis-00.toc
5943 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by f:\GUI\venv\scripts\python.exe
5959 INFO: Analyzing F:\GUI\main.py
6099 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_modul
e\\hook-urllib3.packages.six.moves.py'.
8112 INFO: Processing module hooks...
8112 INFO: Loading module hook 'hook-certifi.py' from 'f:\\GUI\\venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
8127 INFO: Loading module hook 'hook-difflib.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8127 INFO: Excluding import of doctest from module difflib
8127 INFO: Loading module hook 'hook-distutils.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8127 INFO: Loading module hook 'hook-distutils.util.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8127 INFO: Excluding import of lib2to3.refactor from module distutils.util
8127 INFO: Loading module hook 'hook-encodings.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8205 INFO: Loading module hook 'hook-heapq.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8221 INFO: Excluding import of doctest from module heapq
8221 INFO: Loading module hook 'hook-lib2to3.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8361 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8361 INFO: Excluding import of test.support from module multiprocessing.util
8361 INFO: Excluding import of test from module multiprocessing.util
8361 INFO: Loading module hook 'hook-pickle.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8361 INFO: Excluding import of argparse from module pickle
8361 INFO: Loading module hook 'hook-PIL.Image.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8720 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8720 INFO: Excluding import of numpy from module PIL.ImageFilter
8720 INFO: Loading module hook 'hook-PIL.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8720 INFO: Import to be excluded not found: 'FixTk'
8720 INFO: Excluding import of tkinter from module PIL.ImageTk
8720 INFO: Excluding import of PyQt5 from module PIL.ImageQt
8736 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8736 INFO: Import to be excluded not found: 'FixTk'
8736 INFO: Loading module hook 'hook-sysconfig.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8736 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8736 INFO: Loading module hook 'hook-xml.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8782 INFO: Loading module hook 'hook-_tkinter.py' from 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks'...
8907 INFO: checking Tree
8907 INFO: Building Tree because Tree-00.toc is non existent
8907 INFO: Building Tree Tree-00.toc
8970 INFO: checking Tree
8970 INFO: Building Tree because Tree-01.toc is non existent
8970 INFO: Building Tree Tree-01.toc
9032 INFO: checking Tree
9032 INFO: Building Tree because Tree-02.toc is non existent
9032 INFO: Building Tree Tree-02.toc
9063 INFO: Looking for ctypes DLLs
9110 INFO: Analyzing run-time hooks ...
9110 INFO: Including run-time hook 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
9110 INFO: Including run-time hook 'f:\\GUI\\venv\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
9110 INFO: Including run-time hook 'f:\\GUI\\venv\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\rthooks\\pyi_rth_certifi.py'
9126 INFO: Looking for dynamic libraries
9796 INFO: Looking for eggs
9796 INFO: Using Python library C:\Python\python38.dll
9796 INFO: Found binding redirects:
[]
9812 INFO: Warnings written to F:\GUI\build\Removeer\warn-Removeer.txt
9890 INFO: Graph cross-reference written to F:\GUI\build\Removeer\xref-Removeer.html
9921 INFO: checking PYZ
9921 INFO: Building PYZ because PYZ-00.toc is non existent
9921 INFO: Building PYZ (ZlibArchive) F:\GUI\build\Removeer\PYZ-00.pyz
10951 INFO: Building PYZ (ZlibArchive) F:\GUI\build\Removeer\PYZ-00.pyz completed successfully.
10966 INFO: checking PKG
10966 INFO: Building PKG because PKG-00.toc is non existent
10966 INFO: Building PKG (CArchive) PKG-00.pkg
14492 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
14523 INFO: Bootloader f:\GUI\venv\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
14523 INFO: checking EXE
14523 INFO: Building EXE because EXE-00.toc is non existent
14523 INFO: Building EXE from EXE-00.toc
14523 INFO: Copying icons from ['logo.ico']
14523 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
14523 INFO: Writing RT_ICON 1 resource with 194968 bytes
14523 INFO: Updating manifest in F:\GUI\build\Removeer\runw.exe.9trd9vqt
14523 INFO: Updating resource type 24 name 1 language 0
14523 INFO: Appending archive to EXE F:\GUI\dist\Removeer.exe
14539 INFO: Building EXE from EXE-00.toc completed successfully.
after compliting the application will start then when the Toplevel is start you can a blank window will open with a title but there are no icon or no widget. I know that this is for setting icon because when I remove icon in code and reprocess the converting EXE method then the toplevel works good. Please help and give me a good solution!
I'm sorry, I am not good in grammer
Upvotes: 2
Views: 1072
Reputation: 41
Use cx_freeze and add the file on setup.py file the code
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"packages": [
'tkinter',
],
'include_files': [r'icon'] # Here you must add the icon file
}
# GUI applications require a different base on Windows (the default is for
# a console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Gui",
version = "1.0",
description = "A simple Description",
options = {"build_exe": build_exe_options},
executables = [Executable("script.py", base=base, icon=r'icon\icon.ico')])
Upvotes: 1