Python Forum
[Tkinter] Window Icon
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Window Icon
#1
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()
Reply
#2
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]
Reply
#3
(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]
Reply
#4
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.w...s.com/1947
Reply
#5
(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.w...s.com/1947

Ok Let me check all these things one by one
Thank you for replaying Bro.
Reply
#6
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()
Reply
#7
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 342 Mar-17-2024, 09:37 AM
Last Post: deanhystad
Exclamation [PyQt] Setting icon on QAction from outside QGuiApplication gradlon93 3 1,678 Jan-04-2023, 11:37 AM
Last Post: gradlon93
  PyQt6 QAction with icon and string malonn 2 1,618 Sep-12-2022, 11:59 AM
Last Post: malonn
  how to remove icon ilyess68ysl 4 3,581 Oct-15-2021, 10:05 AM
Last Post: ilyess68ysl
  Icon in tkinter menator01 8 4,843 May-03-2020, 02:01 PM
Last Post: wuf
  [Tkinter] Password Reveal Icon Evil_Patrick 2 4,587 Nov-29-2019, 02:20 PM
Last Post: Evil_Patrick
  tkinter window and turtle window error 1885 3 6,623 Nov-02-2019, 12:18 PM
Last Post: 1885
  Button with Image Icon Friend 2 6,767 Jul-25-2019, 09:39 AM
Last Post: Friend
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,264 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  [PyQt] How is this tray icon throbber done? JackDinn 7 4,736 Mar-05-2018, 02:19 PM
Last Post: JackDinn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020