Python Python pystray update_menu, use variable text for item

John332

Newbie
Registriert
Nov. 2023
Beiträge
2
I want to change the text for an item variably. to do this, i tried to update the menu using update_menu(). unfortunately, this didn't work and i couldn't find anything more detailed in the pystray documentation. I hope you can help me. thank you.

Python:
from pystray import Icon as icon, Menu as menu, MenuItem as item
import PIL.Image

image = PIL.Image.new('RGB', (100, 100), 255)

adapter = 'before'
def test():
    global ps
    global adapter
    adapter = 'after'
    ps.update_menu()

ps = icon(name='name', icon=image, menu=menu(
        item(text='Adapter', action=menu(item(text='Test', action=test))),
        item(text=adapter, action=lambda: test()),
        )
    )
ps.run()
 
Hi @_anonymous0815_ ,

Thanks a lot for your answer. But systray is different from pystray, isn't it? But maybe i can use systray as well. I will try it in the next days.
 
John332 schrieb:
Thanks a lot for your answer. But systray is different from pystray, isn't it? But maybe i can use systray as well. I will try it in the next days.
Oh, I'm a bit embarrassed now, I'd only skimmed the code and must have misread it.
I'm really sorry. I didn't want to give you false hope.

:(
 
Zurück
Oben