5

I am working with Tkinter and i keep getting an error message when trying to run the code, could someone help?

from tkinter import *
from tkinter.messagebox import showinfo

def reply(name):
    showinfo(title='Reply', message='Hello %s!' % name)

top = Tk()
top.title('Echo')
top.iconbitmap('py-blue-trans-out.ico')
Label(top, text="Enter your name:").pack(side=TOP)

ent = Entry(top)
ent.pack(side=TOP)
btn = Button(top, text="Submit", command=(lambda: reply(ent.get())))
btn.pack(side=LEFT)
top.mainloop()

I keep getting this error message:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\manage\tkinter103.py", line 9, in <module>
    top.iconbitmap('py-blue-trans-out.ico')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1871, in wm_iconbitmap
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "py-blue-trans-out.ico" not defined
stovfl
  • 14,998
  • 7
  • 24
  • 51

3 Answers3

2

I found the solution of running the script form terminal. It works there, but in my VS code I get the same error as yours.

M--
  • 25,431
  • 8
  • 61
  • 93
Dan
  • 51
  • 5
0

I had a similar problem with a project, and the problem in my case is that the Python file was in one folder called "graphics", whose folder was in another folder where I had all my Python files. If you are using VScode like me, I recommend that you check your file structure.

M--
  • 25,431
  • 8
  • 61
  • 93
0

If your .ico file store in a folder (e.g. ./python/logo.ico) and VS terminal run path that don't include the folder which .ico file is located (e.g. ./python) you will get an error like that one. Solution of that problem --> provide the path of your .ico file using realtive address in icobitmap(./python/logo.ico)