Is it possible to have icon in tkinter menubar in python Is it possible to have icon in tkinter menubar in python tkinter tkinter

Is it possible to have icon in tkinter menubar in python


It is impossible to do what you want if you are on Windows. Tkinter won't allow you to add icons to the menubar. I think this is related to limitations in the windows API that the underlying tk library uses.

Note: menubars are designed for menus, not commands. Placing a command on a menubar will likely frustrate your users, because they will expect that clicking on an item will display a menu.


It is not possible to add an image to menubar, so the submenus of this menubar will have images instead of string names. However, you can use Menubutton widgets, and set their position close to the left top corner of the parent window to have a visually same view with a Menu object. Here's how you can achieve this:

from tkinter import *root = Tk()root.geometry("500x500-500+50")imgvar1 = PhotoImage(file='airplane1.png')mainmenu1 = Menubutton(root, image=imgvar1)mainmenu1.grid(row=0, column=0)submenu1 = Menu(mainmenu1)mainmenu1.config(menu=submenu1)submenu1.add_command(label="Option 1.1")submenu1.add_command(label="Option 1.2")imgvar2 = PhotoImage(file='automobile1.png')mainmenu2 = Menubutton(root, image=imgvar2)mainmenu2.grid(row=0, column=1)submenu2 = Menu(mainmenu2)mainmenu2.config(menu=submenu2)submenu2.add_command(label="Option 2.1")submenu2.add_command(label="Option 2.2")imgvar = PhotoImage(file='eye.gif')button = Button(root, image=imgvar)button.grid(row=0, column=2)

Additionally, I consider this as a kind of bug in Menu, because add_cascade method of Menu has an option image, because it does not return any unknown option error, but it does not show any image either, it just shows a string: "(Image)".


working case :

self.MyImage,self.dictImg={},{}self.ypath='path'self.dictImg[0]='img0.png'self.MyImage['Option'] =PhotoImage(file=self.ypath+os.sep+self.dictImg[0])        self.casmenu.choices.wierdones.add_command(label='Option',image=self.MyImage['Option'],compound='left')

please note: you must indicate compound='left', the relative option to the image=self.MyImage['Option'].