Removing the TK icon on a Tkinter window
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.
Python : How to remove the tkinter icon
As indicated in https://stackoverflow.com/a/18277350/4777984 this is probably the best solution.
import tkinter
import tempfile, base64, zlib
ICON = zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy'
'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc='))
_, 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()
Removing TK from Window Title Python tkinter
First of all, you should not create multiple Tk()
applications in the same program.
The issue occurs because you create the new window (Application) using Tk()
, but you are renaming the title only root
application. This does not rename the title of tk
application. That you create.
If all you want is for the title to be renamed for the window with the label - Window with transparent icon. . You should use tk.title()
(instead of root.title()
) . Example -
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.title("rename")
tk.iconbitmap(default=ICON_PATH)
label = tkinter.Label(tk, text="Window with transparent icon.")
label.pack()
tk.mainloop()
And you do not need multiple tkinter
imports, it does not do anything. Importing tkinter
(or any module) once caches it in sys.modules
, and any time you try to import it again, you get that cached module from sys.modules
.
If you want to create more windows in your application you should use Toplevel
widget for that . Example -
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.title("rename")
tknewwindow = tkinter.Toplevel(tk)
tknewwindow.title("rename1")
tknewwindow.iconbitmap(default=ICON_PATH)
label = tkinter.Label(tknewwindow, text="Window with transparent icon.")
label.pack()
tk.mainloop()
How to replace the icon in a Tkinter app?
To change the icon you should use iconbitmap
or wm_iconbitmap
I'm under the impression that the file you wish to change it to must be an ico file.
import tkinter as tk
root = tk.Tk()
root.iconbitmap("myIcon.ico")
Edit/Remove Tk characters from tkinter window
The red scripty Tk is the app icon.
On some platforms, you can replace that by using the iconbitmap
or iconphoto
functions. On others, you can't override the icon specified in the exe/bundle/etc. So, to do this cross-platform, you'll need to do it in your code, and also in your packaging (assuming you're planning to package and distribute binaries).
If you only care about Windows, iconbitmap
with a Windows .ico file is the right solution. IIRC, on most *nix systems it's iconbitmap
with a .xbm or iconphoto
with a .xpm, while on Mac, it's… well, the app icon (which has to come from the bundle) isn't shown on the window at all, the document icon is shown there, and calling iconbitmap
on a window sets the document icon to the Finder icon for the specified file.
See this thread for an explanation of how to do it from Python.
As far as I know, Tk has no way to remove the app icon. Which is probably a good thing, because many platforms/window managers would end up showing some hideous "default app" in that place. But you can replace it with a 100%-transparent icon, which may be what you want.
The plain black tk is just window title. Give it any other window title, and the "tk" won't appear.
If you've already created a window and want to change its title, just call the title
method:
my_frame.title('My new title, with no tk (except that one)')
Changing icon for only askopenfilename in tkinter, while hiding the main Tk() window in python
Actually you have created two instances of Tk()
:
Tk().iconbitmap(window_icon) # first instance
Tk().withdraw() # 2nd instance
So you just hide the second instance.
Create single instance of Tk()
instead:
root = Tk()
root.withdraw() # keep the root window from appearing
root.iconbitmap(window_icon)
You can use JPEG image as the icon using Pillow
(PIL
clone) module:
from tkinter import Tk
from PIL import ImageTk
root = Tk()
window_icon = ImageTk.PhotoImage(file="icon.jpg")
root.iconphoto(True, window_icon)
How to remove icon of gui from taskbar in tkinter python
Actually, I am using powershell for trying code and at that stage I found that even after overrideredirect as true it is showing me the icon in taskbar, and that still shows it even when I ran the overrideredirect again.
I think it is anonymous.
Related Topics
Could Not Find a Version That Satisfies the Requirement <Package>
Split Views.Py in Several Files
Matplotlib: Adding an Axes Using the Same Arguments as a Previous Axes
Remove Non-Ascii Characters from Pandas Column
Groupby Column and Filter Rows with Maximum Value in Pyspark
Run Powershell Function from Python Script
Gunicorn Autoreload on Source Change
Installing Numpy and Scipy on 64-Bit Windows (With Pip)
Web Scraping Dynamic Content with Python
Value Error Trying to Install Python for Windows Extensions
Extracting Specific Columns in Numpy Array
Read Unicode Characters from Command-Line Arguments in Python 2.X on Windows
How to Use _Init_.Py to Define Global Variables
Reading the Target of a .Lnk File in Python
Pandas Style Function to Highlight Specific Columns