Why isn't .ico file defined when setting window's icon?
You need to have favicon.ico
in the same folder or dictionary as your script because python only searches in the current dictionary or you could put in the full pathname. For example, this works:
from tkinter import *
root = Tk()
root.iconbitmap(r'c:\Python32\DLLs\py.ico')
root.mainloop()
But this blows up with your same error:from tkinter import *
root = Tk()
root.iconbitmap('py.ico')
root.mainloop()
How to set window's icon in Perl to some .ico file on Windows 7?
As Alexandr suggested, I asked J-L from bribes.org to build the module for Perl64bit and he did so.
So now the icon can be set with TK::Icon also on Perl 64bit.
The ppm install command is:
ppm install http://www.bribes.org/perl/ppm64/Tk-Icon.ppd
Which file formats can I use for tkinter icons?
Let's start by reading the documentation!
The documentation at effbot.org says the following regarding iconbitmap(bitmap=None)
So here's the documentation aboutSets or gets the icon bitmap to use when this window is iconified. This method is ignored by some window managers (including Windows).
Note that this method can only be used to display monochrome icons. To display a color icon, put it in a
Label
widget and display it using theiconwindow
method instead.Same as
wm_iconbitmap
.
iconwindow(window=None)
:According to this other documentation, which actually says the same things as the docstrings of the homonymous method forSets or gets the icon window to use as an icon when this window is iconified. This method is ignored by some window managers (including Windows).
Same as
wm_iconwindow
.
window
The new icon window. If omitted, the current window is returned.
tkinter
in (at least) Python 2.7, 3.5 and 3.6:So here's the original Tk documentation:
wm_iconbitmap(self, bitmap=None, default=None)
Set bitmap for the iconified widget to
bitmap
. Return the bitmap if None is given.Under Windows, the
default
parameter can be used to set the icon for the widget and any descendents that don't have an icon set explicitly.default
can be the relative path to a.ico
file (example:root.iconbitmap(default='myicon.ico')
). See Tk documentation for more information.
From my understanding of
wm iconbitmap window ?bitmap?
If bitmap is specified, then it names a bitmap in the standard forms accepted by Tk (see the
Tk_GetBitmap
manual entry for details). This bitmap is passed to the window manager to be displayed in window's icon, and the command returns an empty string. If an empty string is specified forbitmap
, then any current icon bitmap is canceled forwindow
. Ifbitmap
is specified then the command returns an empty string. Otherwise, it returns the name of the current icon bitmap associated withwindow
, or an empty string ifwindow
has no icon bitmap.
Tcl
, here window
is your toplevel window (either an instance of Tk
or Toplevel
).Not very concrete and thus helpful answer so far.On the Windows operating system, an additional flag is supported:
wm iconbitmap window ?-default? ?image?
If the
-default
flag is given, the icon is applied to all toplevel windows (existing and future) to which no other specific icon has yet been applied.In addition to bitmap image types, a full path specification to any file which contains a valid Windows icon is also accepted (usually
.ico
or.icr
files), or any file for which the shell has assigned an icon.Tcl will first test if the file contains an icon, then if it has an assigned icon, and finally, if that fails, test for a bitmap.
My conclusion
The iconbitmap
function (or method, depending on the programming language) should be used to set a bitmap image to the window when the window is iconified.
On Windows you're allowed to set a full path specification to any file which contains a valid Windows icon is also accepted (usually .ico
or .icr
files), or any file for which the shell has assigned an icon.
So which images are bitmaps?
xbm
andxpm
(for X Window System)According to the Wikipedia article to which I linked "bitmap" to above:
The X Window System uses a similar
xbm
format for black-and-white images, andxpm
for color images.
...BMP file format
Netpbm format
.wbmp
ILBM
...
xbm
image for the icon, it may not work on your platform because xbm
are bitmaps for X Window System.Note: even after this answer you may still have problems!
Other possible useful articles
- Set window icon
- tkinter TclError: error reading bitmap file
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")
Related Topics
Powersets in Python Using Itertools
How to Save the Pandas Dataframe/Series Data as a Figure
How to Suppress or Capture the Output of Subprocess.Run()
How to Use Python-Docx to Replace Text in a Word Document and Save
Python Wildcard Search in String
Getting Gradient of Model Output W.R.T Weights Using Keras
Crontab Not Executing a Python Script
Python Insert Numpy Array into SQLite3 Database
How Does Sklearn.Svm.Svc's Function Predict_Proba() Work Internally
Create Spark Dataframe. Can Not Infer Schema for Type
How to Crop the Internal Area of a Contour
Conditional with Statement in Python
Memoization Library for Python 2.7
Simple Way to Query Connected Usb Devices Info in Python
Memory Error When Using Pandas Read_Csv
How to Modify Procfile to Run Gunicorn Process in a Non-Standard Folder on Heroku