Problems with setting icon for your Tkinter app in Python

I used root.iconbitmap("icon.ico") in my code and uploaded a picture with the same name, but I code error while trying to put it on the program icon. Has anyone figured out what the problem is? Is it a bug?

please send the repl link?

1 Like

I don’t want to do it, but there is my code:


(You can try to do it in your own Repl)

… I can’t copy paste that into a repl

And there it is:

Just use iconbitmap. You can copy paste it from photo by Google Lens.

I don’t understand why you can’t jjust copy paste that portion in and I want the full code because I know full well that no human being is unerring and that the error could be somewhere different than you suspect

1 Like

But wait, you can try to set icon in your own Repl. If you will be able to do it, it is fault in my code. Just import Tkinter, create Tk, set the size and try to set the picture also.

I have provided all the necessary information. Thank you for your understanding.

no you have not provided all necessary information. However, while I do not even use tkinter, I can tell you what probably happened merely by a quick google. You’re basically using a ico setter that only lets you set black and white images (according to this). Thus, you can try using the following code instead:

root = Tk()
img = PhotoImage(file='your-icon')
root.tk.call('wm', 'iconphoto', root._w, img)
2 Likes

did this solve your problem?

Hello , sorry for the delay. No, there isn’t.

couldn’t regonize data in image file means you have a corrupted ico file

1 Like

Okay, I will try another one.

1 Like

at least that’s what I think

Thank you really much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.