I'm facing a weird problem with Python Tkinter: code that runs correctly on Windows, on Ubunbtu doesn't work because for some unknown reason it is unable to load the icon file in the folder where the script is located if I don't use the full path, returning the error Exception has occurred: TclError Bitmap im.ico is not defined
suppose to have a
mycode.py with this hello world
from tkinter import * root = Tk() a = Label(root, text ="Hello World") a.pack() root.iconbitmap('im.ico') root.mainloop()
im.ico is a file in the same path of
If i run this on Windows no problem at all. if I run it on Ubuntu it crashes reporting that
im.ico is not defined and to make it runnable I'm forced to put the absolute path
root.iconbitmap('/home/andrew/im.ico') for icon load.
That isn't what I want.
So in order to normalize path I have also tried to use
ICONPATH = os.path.join(os.path.dirname(__file__), 'im.ico') root.iconbitmap(ICONPATH)
but I get same error Exception has occurred: TclError Bitmap path/im.ico is not defined
and strangely in the error output
path/im.ico reported in the error itself exists and is correct
Why this error happens? How could I fix making sure that the file in current folder where script is located is loaded correctly?