moses-palmer / pystray

GNU General Public License v3.0
472 stars 59 forks source link

No menu in xfce #159

Closed baztian closed 7 months ago

baztian commented 7 months ago

I'm on XFCE 4.18.1 and unfortunately the menu doesn't work. pystray==0.19.5 The tray icon is visible though

from pystray import MenuItem as item
import pystray
from PIL import Image, ImageDraw

# Function to create an image
def create_image(width, height, color1, color2):
    # Generate an image and draw a pattern
    image = Image.new('RGB', (width, height), color1)
    dc = ImageDraw.Draw(image)
    dc.rectangle(
        [width // 2, 0, width, height // 2],
        fill=color2
    )
    dc.rectangle(
        [0, height // 2, width // 2, height],
        fill=color2
    )

    return image

# The function to call when the menu item is clicked
def on_clicked(icon, item):
    if item.text == 'Say Hello':
        print('Hello, world!')
    elif item.text == 'Exit':
        icon.stop()

# Create a menu item
menu = (item('Say Hello', on_clicked), item('Exit', on_clicked))

# Create a tray icon with the above menu
icon = pystray.Icon("test_icon", create_image(64, 64, 'black', 'blue'), "Title", menu)

# Run the icon
icon.run()
moses-palmer commented 7 months ago

Thank you for your report,

I suspect this is because you are using the fallback XOrg backend which does not support menus. You can check this by checking the class of you menu instance. Only implementations where the class attribute HAS_MENU supports menus.

If this is not the case, please reopen this issue.