I try to install and run package with gui app in tkinter
. I am not able to display app icon after installation. What should I change to make it possible? Here is my package directory tree:
gui_app/
| gui_app/
| __init__.py
| __main__.py
| img/
| icon.gif
| setup.py
setup.py
contains:
from setuptools import setup
from gui_app import __version__
setup(
name='gui_app',
version=__version__,
packages=['gui_app'],
data_files=[('', ['img/icon.gif'])],
entry_points={'gui_scripts': ['gui_app = gui_app.__main__:main'],},
)
To load my icon I have tried different approaches described here: pkgutil, importlib.resources. Unfortunately none of them worked for me. I may do something wrong. Here is code which I ended up with:
import tkinter as tk
from importlib.abc import ResourceReader as res
def get_path_before_install():
return 'img/icon.gif'
def get_path_after_install():
return res.resource_path('.', 'icon.gif')
def display_gui():
root = tk.Tk()
icon_path = get_path_after_install()
icon = tk.PhotoImage(file=str(icon_path))
root.iconphoto(False, icon)
root.mainloop()
def main():
display_gui()
if __name__ == '__main__': main()
When I use $ pip install .
and then $ gui_app
it produces FileNotFoundError
. How can I correct it to display icon after installation?