Question

Does anybody know how to make the icon not show up? I'm looking for a way to have no icon at all.

Was it helpful?

Solution

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.

OTHER TIPS

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='))

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

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()

Update:

The slightly modified code (try clause instead of if TkVersion) produces a transparent (no) icon on:

Linux (Mint 18.1), Python 2.7

Linux (Mint 18.1), Python 3.5.1

Windows 10, Python 2.7.13

It produces a black icon (does not work) on:

Windows 8.1, Python 3.6

A rather old question, but the solutions weren't working for me. I found a partial simple solution, with a follow-up question of my own.

The partial solution (Tk 8.5, see below) - using PhotoImage's blank() method:

from Tkinter import *

root=Tk()

icon=PhotoImage(height=16, width=16)
icon.blank()

root.tk.call('wm', 'iconphoto', self.master._w, icon)

root.mainloop()

On Python 2.7, Windows 10, this works fine, producing the desired "no icon" for your new app.

However, on Python 3.6, Win 8.1, this jams the GUI, which I think is related to the newer Tk 8.6, and though I found that the new 8.6 notation of using wm_iconphoto() does pass unjammed in this case:

try:
    from tkinter import *
except:
    from Tkinter import * 

root=Tk()

#Identical for Py2.7/Tk8.5 and Py3.5/Tk8.6
icon=PhotoImage(height=16, width=16)
icon.blank()

#Picking a notaion based on Tk version to avoid jamming
try:
    root.wm_iconphoto('True', icon)   #New Tk 8.6 style        
else:
    #Jams Python 3.5 with Tk 8.6 on Windows
    root.tk.call('wm', 'iconphoto', self.master._w, icon)   



root.mainloop()

It produces a black icon on 3.6, instead of the transparent one in case of 2.7/8.5.

There might be a way to set the pixels transparent one by one using "transparency set" - http://wiki.tcl.tk/1449

However, I don't know if it's even doable via Tkinter. God favors the bold, someone else's turn though?

Updated question: Why doesn't this work on Py3.6/Windows?

Alternative to @ubomb's soluation 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)

effbot.org link for more details:

http://effbot.org/tkinterbook/photoimage.htm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top