pystray icon indicating copy to clipboard operation
pystray copied to clipboard

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

Open okelet opened this issue 2 years ago • 2 comments

Environment:

  • Ubuntu 22.04
  • Python 3.10
  • Poetry 1.1.14
  • Pystray from pip (poetry init, poetry add pystray)

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 avatar Jul 28 '22 19:07 okelet

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.

okelet avatar Jul 31 '22 10:07 okelet

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 avatar Aug 02 '22 11:08 moses-palmer

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

moses-palmer avatar Nov 29 '22 17:11 moses-palmer

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

okelet avatar Nov 30 '22 07:11 okelet