Python Forum
[Tkinter] Window Icon - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Window Icon (/thread-21843.html)



Window Icon - Evil_Patrick - Oct-17-2019

Trying to change Window's icon

[Image: Untitled.png]

icon = r'C:\Users\Evil Patrick\Desktop\desktop-solid.ico'

from tkinter import *

root = Tk()

root.minsize(300, 200)
root.title("My Window")
root.iconbitmap(icon)

root.mainloop()



RE: Window Icon - steve_shambles - Oct-17-2019

It is not finding your icon file.

I changed your first line to
icon = 'test.ico'

and had test.ico in current dir, and it works fine.

[Image: ico.png]


RE: Window Icon - Evil_Patrick - Oct-17-2019

(Oct-17-2019, 12:34 PM)steve_shambles Wrote: It is not finding your icon file.

I changed your first line to
icon = 'test.ico'

and had test.ico in current dir, and it works fine.

[Image: ico.png]


Still same Dude

[Image: Untitled.png]


RE: Window Icon - steve_shambles - Oct-17-2019

All I can think of then is that you either have
a damaged .ico file, or it doesn't exist,
or maybe it has something to do with your IDE
which I have never used (I'm still happily using IDLE),
or something to do with your OS, I'm using windows 7.

None of these seems likely though, so I'm sorry, I'm stumped bro.
I did a write up on this as a code snippet where you can
download some icons and test code, maybe this is worth a look to you?
See the second code snippet 52-Change Tk Window Icon

https://wordpress.com/post/stevepython.wordpress.com/1947


RE: Window Icon - Evil_Patrick - Oct-18-2019

(Oct-17-2019, 09:09 PM)steve_shambles Wrote: All I can think of then is that you either have
a damaged .ico file or it doesn't exist,
or maybe it has something to do with your IDE
which I have never used (I'm still happily using IDLE),
or something to do with your OS, I'm using windows 7.

None of these seems likely though, so I'm sorry, I'm stumped, bro.
I did a write up on this as a code snippet where you can
download some icons and test code, maybe this is worth a look to you?
See the second code snippet 52-Change Tk Window Icon

https://wordpress.com/post/stevepython.wordpress.com/1947

Ok Let me check all these things one by one
Thank you for replaying Bro.


RE: Window Icon - steve_shambles - Oct-18-2019

You can use this code to check if your .ico file is valid.

This will run a file selector so you can manually choose
any .ico file from anywhere and it will use that icon.

from tkinter import filedialog, Tk

root = Tk()

#Open file dialog
file_selected = filedialog.askopenfilename(filetypes=[('ico files','*.ico')])

root.minsize(300, 200)
root.title("My Window")
root.iconbitmap(file_selected)
 
root.mainloop()



RE: Window Icon - Evil_Patrick - Oct-18-2019

(Oct-18-2019, 11:00 AM)steve_shambles Wrote: You can use this code to check if your .ico file is valid.

This will run a file selector so you can manually choose
any .ico file from anywhere and it will use that icon.

from tkinter import filedialog, Tk

root = Tk()

#Open file dialog
file_selected = filedialog.askopenfilename(filetypes=[('ico files','*.ico')])

root.minsize(300, 200)
root.title("My Window")
root.iconbitmap(file_selected)
 
root.mainloop()

Sorry my .ico was now valid
Thanks for your help