Tkinter: add icon to menu item


Dylan Logan

I have a fully functional TkInter right click context menu with 4 items and 1 separator, but I'm trying to figure out how to display icons in each item, I managed to get the items to display as icons, but removing the actual Visibility of text, which is not ideal. Does anyone know how to make the text appear to the right of the icon?

I'll paste the code snippet and the actual menu.

try:
    def rClick_Copy(e, apnd=0):
        e.widget.event_generate('<Control-c>')
    def rClick_Cut(e):
        e.widget.event_generate('<Control-x>')
    def rClick_Paste(e):
        e.widget.event_generate('<Control-v>')
    def rClick_SelectA(e):
        e.widget.select_range(0, 'end')
        e.widget.icursor('end')
     e.widget.focus()
     nclst=[
            ('Cut', lambda e=e: rClick_Cut(e)),
            ('Copy', lambda e=e: rClick_Copy(e)),
            ('Paste', lambda e=e: rClick_Paste(e)),
            ('Seperator', ''),
            ('Select All', lambda e=e: rClick_SelectA(e)),
            ]
     rmenu = Menu(None, tearoff=0, takefocus=0)
     for (txt, cmd) in nclst:
         if txt == 'Seperator':
             rmenu.add_separator()
             continue
         rmenu.add_command(label=txt, command=cmd,) #image=self._img4 <add this in when using icons.
     rmenu.tk_popup(e.x_root+40, e.y_root+10,entry="0")
except TclError:
    print ' - rClick menu, something wrong'
    pass

Right-click menu:

right-click menu

Right-click menu with icons:

Right-click menu with icons

Bryan Oakley

Like buttons, menu buttons, and labels, menu items can support both text and images. To do this, you have to use that compoundoption to tell tkinter where you want the image to appear relative to the text. The available option values ​​are bottom, center, left, none, right, and top.

For example, to make the image appear on the left, use compound='left':

rmenu.add_command(label=txt, image=self._img4, compound='left', command=cmd)

Note: Valid locations are somewhat platform-dependent. For example, on OSX, the image always seems to be displayed to the left of the text, no matter what you set it to compound.

Related


Tkinter: add icon to menu item

Dylan Logan I have a fully functional TkInter right click context menu with 4 items and 1 separator, but I'm trying to figure out how to display icons in each item, I managed to get the items to display as icons, but remove the actual Visibility of text, which

Tkinter: add icon to menu item

Dylan Logan I have a fully functional TkInter right click context menu with 4 items and 1 separator, but I'm trying to figure out how to display icons in each item, I managed to get the items to display as icons, but remove the actual Visibility of text, which

Tkinter: add icon to menu item

Dylan Logan I have a fully functional TkInter right click context menu with 4 items and 1 separator, but I'm trying to figure out how to display icons in each item, I managed to get the items to display as icons, but remove the actual Visibility of text, which

Tkinter: add icon to menu item

Dylan Logan I have a fully functional TkInter right click context menu with 4 items and 1 separator, but I'm trying to figure out how to display icons in each item, I managed to get the items to display as icons, but removing the actual Visibility of text, whi

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Add icon to menu item when showAsAction="never"

Mohamed Essam I have items in my menu and this is one of them <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/settings" android:title="Settings" app:showAsAct

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Add icon/menu item for application in XFCE

all_meije I'm running Debian (Stretch) with XFCE and many applications do not appear in the menu (Whisker Menu in my case). For example, I often run remote sessions with VNC, and at the moment, I can only launch a VNC viewer from the terminal. Ideally it would

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Ionic - How to add icon on secondary menu item?

Gabriel Augusto I'm new to ionic 2, I created a side menu app using ionic CLI, I only have a few pages, but now I want to add a different icon to each menu item, how can I do that? Here is my app.html: <ion-menu [content]="content"> <ion-header> <ion-too

Add icon to menu item when showAsAction="never"

Mohamed Essam I have items in my menu and this is one of them <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/settings" android:title="Settings" app:showAsAct

Add icon to menu item when showAsAction="never"

Mohamed Essam I have items in my menu and this is one of them <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/settings" android:title="Settings" app:showAsAct

Add icon/menu item for application in XFCE

all_meije I'm running Debian (Stretch) with XFCE and many applications do not appear in the menu (Whisker Menu in my case). For example, I often run remote sessions with VNC, and at the moment, I can only launch a VNC viewer from the terminal. Ideally it would

Add clickable help icon to navbar menu item in bootstrap navbar

佐尔坦 · 塔玛西 (ZoltánTamási) I'm trying to add a small clickable and hoverable help icon that floats to the right of the corresponding navbar menu item. My problem is that bootstrap applies its styles in a way that doesn't seem like an easy task. My icons will loo

Add clickable help icon to navbar menu item in bootstrap navbar

佐尔坦 · 塔玛西 (ZoltánTamási) I'm trying to add a small clickable and hoverable help icon that floats to the right of the corresponding navbar menu item. My problem is that bootstrap doesn't seem like an easy task to apply its styles. My icons will look like this (

Add clickable help icon to navbar menu item in bootstrap navbar

佐尔坦 · 塔玛西 (ZoltánTamási) I'm trying to add a small clickable and hoverable help icon that floats to the right of the corresponding navbar menu item. My problem is that bootstrap applies its styles in a way that doesn't seem like an easy task. My icons will loo

Add clickable help icon to navbar menu item in bootstrap navbar

佐尔坦 · 塔玛西 (ZoltánTamási) I'm trying to add a small clickable and hoverable help icon that floats to the right of the corresponding navbar menu item. My problem is that bootstrap doesn't seem like an easy task to apply its styles. My icons will look like this (

Add clickable help icon to navbar menu item in bootstrap navbar

佐尔坦 · 塔玛西 (ZoltánTamási) I'm trying to add a small clickable and hoverable help icon that floats to the right of the corresponding navbar menu item. My problem is that bootstrap applies its styles in a way that doesn't seem like an easy task. My icons will loo

The icon of the menu item in the layout

Drake I have a menu: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto"> <group android:id="@+id/nav_items"> <item an

Python Tkinter - menu icon not showing

maicol07 I am using tkinter to build a menu, but the icons are not showing. can you help me? mb=Menu(w) w.config(menu=mb) fm=Menu(mb,tearoff=0) om=Menu(mb,tearoff=0) hm=Menu(mb,tearoff=0) mb.add_cascade(label=_("File"),menu=fm) fm.add_command(label=_("Esci"),

Python Tkinter - menu icon not showing

maicol07 I am using tkinter to build a menu, but the icons are not showing. can you help me? mb=Menu(w) w.config(menu=mb) fm=Menu(mb,tearoff=0) om=Menu(mb,tearoff=0) hm=Menu(mb,tearoff=0) mb.add_cascade(label=_("File"),menu=fm) fm.add_command(label=_("Esci"),

Python Tkinter - menu icon not showing

maicol07 I am using tkinter to build a menu, but the icons are not showing. can you help me? mb=Menu(w) w.config(menu=mb) fm=Menu(mb,tearoff=0) om=Menu(mb,tearoff=0) hm=Menu(mb,tearoff=0) mb.add_cascade(label=_("File"),menu=fm) fm.add_command(label=_("Esci"),