Removing the TK icon on a Tkinter window
Solution 1
On Windows
Step One:
Create a transparent icon using either an icon editor, or a site like rw-designer. Save it as transparent.ico
.
Step Two:
from tkinter import *
tk = Tk()
tk.iconbitmap(default='transparent.ico')
lab = Label(tk, text='Window with transparent icon.')
lab.pack()
tk.mainloop()
On Unix
Something similar, but using an xbm
icon.
Solution 2
Similar to the accepted answer (with the con of being uglier):
import tkinter
import tempfile
ICON = (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00'
b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00'
b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64
_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
icon_file.write(ICON)
tk = tkinter.Tk()
tk.iconbitmap(default=ICON_PATH)
label = tkinter.Label(tk, text="Window with transparent icon.")
label.pack()
tk.mainloop()
It just creates the file on the fly instead, so you don't have to carry an extra file around. Using the same method, you could also do an '.xbm' icon for Unix.
Edit: The ICON
can be shortened even further thanks to @Magnus Hoff:
import base64, zlib
ICON = zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy'
'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc='))
Solution 3
Based on previous responses i used this solution:
from PIL import ImageTk
import zlib,base64
import Tkinter
icon=zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy'
'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc='))
root=Tkinter.Tk()
image=ImageTk.PhotoImage(data=icon)
root.tk.call('wm', 'iconphoto', root._w, image)
root.mainloop()
Solution 4
As far as I know, the closest you will get to a "blank" icon is using one that's the same color as the window title bar. But then again a lot of users use different color themes, so it won't go over very well.
However if you use py2exe you can use something like Resource Hacker to swap the icon. But in the python programs text state, the best you can do is replace. Sort of how Jar files use the java icon, tkinter apps will have the TK icon. After all...like java, your app is being translated by an intermediate program. Since another program is running your code, you have to modify that other program. Luckily python/tk is a bit more flexible than the JVM in terms of icons so you can replace the icon. But removing it entirely isn't currently an option.
-John
Solution 5
Alternative to @ubomb's solution for adding custom images by utilizing Tkinter.PhotoImage
's built-in support for processing .gif
images.
From file:
icon = Tkinter.PhotoImage(file="logo.gif")
from base64:
gif_base64_string = """ R0lGODdhEAAQAIcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4O Dg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEh ... 4B8AAP9Ci/4HoLTpfwD+qV4NoHVAADs= """
icon = Tkinter.PhotoImage(data=gif_base64_string)
Visit the undermentioned link for more details: //effbot.org/tkinterbook/photoimage.htm
Related videos on Youtube
Evan Fosmark
Updated on July 09, 2022Comments
-
Evan Fosmark almost 2 years
How to remove tkinter icon from title bar in it's window
-
wordsforthewise about 9 yearshow did you get the 'ICON = (...' in that format? I'm struggling... stackoverflow.com/questions/29507890/…
-
ubomb about 9 yearsIt was a pain to do. I used the rw-designer that @Stobor mentioned in his answer and generated a transparent .ico file. I then opened up the binary file and copy/pasted the data into my python program. I noticed there was a lot of repetition, so I shortened it some - hence the
b'\x00'*1282 + b'\xff'*64
. It might be possible to simplify further if you look up the .ico format specs, but that was good enough for what I was doing. -
Peter Wood about 8 yearsYou can use the
BitmapImage
orPhotoImage
classes to convert the string without creating a temporary file. -
ubomb about 8 years@PeterWood I get
_tkinter.TclError: bitmap "pyimage1" not defined
when I runtk.iconbitmap(default=ICON_PATH)
using theBitmapImage
class and_tkinter.TclError: couldn't recognize image data
when I try creating thePhotoImage
object. -
MarredCheese about 7 yearsRather than creating an icon, you can just Google "blank icon" and download one. For instance: iconspedia.com/icon/blank-icon-44576.html
-
Stobor about 7 years@MarredCheese Yes, that's an option too, but then you have to comply with the licence details of whichever designer created the icon. They shouldn't be too bad, though, so it's a good idea.
-
Stobor about 7 yearsThe best solution is actually Dario's answer below where you can embed the transparent icon into the code, and thus not have to have an extra file in your codebase.
-
Stobor about 5 yearsUpdated questions should be posted as new questions, with a link to the old one. Questions posted in answers will often not be noticed for a long time...
-
R. Navega over 2 yearsThe benefit of this method is that it's done in memory, no need for HD writes