_tkinter.TclError: bitmap "pyimage2" not defined

I want to display the icon in the menu bar, so using this information , I encoded this:

img = Image.open("help.png") 
menubar.add_cascade(label="Help",menu=helpmenu,bitmap=ImageTk.PhotoImage(img))

I got this error:

Traceback (most recent call last):
  File "mine.py", line 67, in <module>
    m.menus(root)
  File "mine.py", line 55, in menus
     menubar.add_cascade(label="Help",menu=helpmenu,bitmap=ImageTk.PhotoImage(img))
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2699, in add_cascade
    self.add('cascade', cnf or kw)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2696, in add
    self._options(cnf, kw))
_tkinter.TclError: bitmap "pyimage2" not defined

How to fix it?

+4
source share
1 answer

To display PhotoImage, you must use the attribute image, not bitmap.
You can also simply open the image file directly usingImageTk.PhotoImage(file='...')

Thus, you can use the following code to display the image in the menu:

img = ImageTk.PhotoImage(file="help.png") 
menubar.add_cascade(label="Help", menu=helpmenu, image=img)
+1
source

All Articles