Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pystray systray icon

Tags:

python

systray

I want to use pystray module in python to create a system tray app on Windows. Until now I managed to write this:

import pystray
from PIL import Image

image = Image.open("image.gif")
icon = pystray.Icon(name ="SPAM!", icon =image, title ="MOBASuite", menu =None)
icon.run()

I had a hard time to find out how this works. Its not clearly explained in a documentation.

How can I create a menu after rightclicking on the icon and how can I add items to the menu and set default one, which should be called if I click on the icon with left button. And how can I update the icon? If I run the this program, 3 icons are created and Imust hover mouse over them to become one icon. Same thing when I close the program.

like image 660
Jakub Bláha Avatar asked Nov 03 '17 11:11

Jakub Bláha


1 Answers

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

def action():
    pass

image = Image.open("image.jpg")
menu = (item('name', action), item('name', action))
icon = pystray.Icon("name", image, "title", menu)
icon.run()

This work for me

I recomend use lambda to call a method

item('Call something', lambda :  method())
like image 98
Sebastin Ignacio Camilla Trinc Avatar answered Oct 05 '22 10:10

Sebastin Ignacio Camilla Trinc