Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the TK icon on a Tkinter window

How to remove tkinter icon from title bar in it's window

like image 214
Evan Fosmark Avatar asked Feb 15 '09 00:02

Evan Fosmark


People also ask

How do I hide the Tk window in Python?

However, to hide the Tkinter window, we generally use the “withdraw” method that can be invoked on the root window or the main window. In this example, we have created a text widget and a button “Quit” that will close the root window immediately.

What does window Tk () mean?

Tkinter is a Python package which comes with many functions and methods that can be used to create an application. In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application.

How do you disable the Close button in tkinter?

Disable Exit (or [ X ]) in Tkinter Window To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.

Is Tk and tkinter the same?

Tkinter is a Python binding to the Tk GUI toolkit. Tk is the original GUI library for the Tcl language. Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python interpreter.


2 Answers

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.

like image 132
Stobor Avatar answered Sep 23 '22 05:09

Stobor


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='))
like image 34
ubomb Avatar answered Sep 25 '22 05:09

ubomb