moses-palmer / pystray

GNU General Public License v3.0
461 stars 57 forks source link

Icon and Menu not shown when running from virtualenv (Poetry) #126

Closed okelet closed 1 year ago

okelet commented 1 year ago

Environment:

Running the code below (taken from the examples) without Poetry runs fine (python3 test.py), but with Poetry (poetry run python3 test.py) the icon is not shown (just an empty space), nor is the menu when clicked; the tooltip (test name) is shown in both cases.

from pystray import Icon, Menu, MenuItem
from PIL import Image, ImageDraw

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

# In order for the icon to be displayed, you must provide an icon
icon = Icon(
    'test name',
    icon=create_image(64, 64, 'black', 'white'),
    menu=Menu(
        MenuItem('Click', lambda: print("Clicked")),
    )
)

# To finally show you icon, call run
icon.run()
okelet commented 1 year ago

Found this post with a similar problem, that fixed it using vext. Tried and works fine for me.

Perhaps, a reference to this in the README would be useful for other people.

moses-palmer commented 1 year ago

From reading the answers to the linked question, it seems that installing pygobject would be the preferable way to solve the problem. Did you try that? That is what the documentation currently recommends.

vext appears to just provide access to the system packages, so installing python-gi or similar on the end user system is still required.

moses-palmer commented 1 year ago

I will close this issue due to lack of feedback. If you think this is incorrect, please reopen.

okelet commented 1 year ago

Sorry, this was a side personal project, that is currently a bit abandoned. Will try to update in a few days.