• We did not send an email asking for donations - please read this post.

I do not knows how to noted a file path in tkinter (python)

fremis

New Member
Joined
Sep 16, 2022
Messages
1
Reaction score
0
Credits
13
so i want to put a icon picture in a tkinter window but i don't known how to noted a path after root.inconbitmap(""). and when i just write the picture name it comes an error written ;;
_tkinter.TclError: bitmap "picture.ico" not defined
if someone can help me to fix it out it will be great
and sorry for my bad English (I am french)
 


JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,563
Reaction score
2,224
Credits
11,524
Where is your icon stored?
What you have at the moment assumes that the icon file is in the current working directory.

If your .ico file is in a different directory, you’ll need to provide the path to the icon file.
Either using an absolute path.
e.g.
Python:
root.iconbitmap('/path/to/picture.ico')
Where /path/to/ is the fully qualified path to the file picture.ico.

Or by using a relative path.
e.g.
Python:
root.iconbitmap('./subdir/picture.ico')
Where ./subdir/ is a sub directory of the current working directory.

Or if the file is in a directory that is higher in the tree than the working directory, you would use a number of instances of ../ to traverse upwards through the tree.
E.g.
Python:
root.iconbitmap('../../somedir/picture.ico')
Means the icon file is two levels up from the current working directory and inside a sub-directory there called somedir.

So you need to make sure that the icon file is somewhere appropriate AND that you provide the correct path to it in your Python script.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top