Python Forum

Full Version: _tkinter.TclError: bitmap "Icon.gif" not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to change the icon of the tkinter window for the following code:
from tkinter import * # gives access to tkinter GUI library

def hello():
    name = textbox1.get() # gets name from textbox1
    print = "Hello " + name # creates Hello name string 
    textbox2["text"] = print # prints that string in textbox2

window = Tk() # opens tkinter window
window.title("Names") # sets title of the window as names
window.geometry("1000x1000") # dimentions
window.wm_iconbitmap("Icon.gif") # changes tkinter window icon 
window.configure(background  = "black") # sets window background to green

logo = PhotoImage(file = "logo.gif") # displays logo.gif in a label widget
logoimage = Label(image = logo) # this can't be changed while the program is running 
logoimage.place(x = 50, y = 20, width = 200, height = 120) # position and dimentions

textbox1 = Entry(text = "") # creates textbox1 where data is entered 
textbox1.place(x = 145, y = 200, width = 125, height = 25) # position and dimentions
textbox1["bg"] = "white" # white background 
textbox1["fg"] = "black" # black font

label1 = Label(text = "Enter a name") # creates label with this text
label1.place(x = 20, y = 200, width = 125, height = 25) # position and dimentions
label1["bg"] = "red" # red background 
label1["fg"] = "blue" # blue font

textbox2 = Message(text = print) # creates textbox1 displaying the variable print
textbox2.place(x = 145, y = 250, width = 125, height = 25) # position and dimentions
textbox2["bg"] = "white" # white background 
textbox2["fg"] = "black" # black font

button1 = Button(text = "Press me", command = hello) # creates button which runs the hello sub-program
button1.place(x = 20, y = 250, width = 125, height = 25) # position and dimentions
button1["bg"] = "blue" # blue background 
button1["fg"] = "red" # red font

window.mainloop() # keeps program running 
But I keep getting this error message:

Error:
File "c:/Users/djwil/Documents/python/learning python/Chapter 17 - more Tkinter/Ch17-c1.py", line 11, in <module> window.wm_iconbitmap("Icon.gif") # changes tkinter window icon File "C:\Users\djwil\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2071, in wm_iconbitmap return self.tk.call('wm', 'iconbitmap', self._w, bitmap) _tkinter.TclError: bitmap "Icon.gif" not defined
I'm not sure why I'm getting this error as I've saved the icon.gif file in the same folder as the program itself. Can anyone help?
How about next time you post you use a topic that is related to the question? For this question you could use "Help with tkinter wm_iconbitmap".

While composing that concise and informative topic you may have decided to do a google search on wm_iconbitmap and "not defined". This would take you directly to several posts on the same question that all say "for windows the icon file type has to be .ico"

The error message from tkinter is not very good, but this is a well known, and common, problem.
Hi djwilson0495

img = PhotoImage(file='Icon.gif')
window.tk.call('wm', 'iconphoto', window._w, img)
Tested under Ubuntu 18.04 only!
wuf :-)