0
import pystray
from PIL import Image
from importlib import reload
import os
import webbrowser

# Image for the tray
image = Image.open("image.png")

# Triggers for right click
def stop(icon, item):
    icon.stop()

def ss(icon, item):
    import discord

def edit(icon, item):
    os.system('config.json')

def git(icon, item):
    webbrowser.open('github')

def support(icon, item):
    webbrowser.open('discord')

# Buttons for right click
icon = pystray.Icon("Hydisc", image, menu=pystray.Menu(
    pystray.MenuItem("Start", ss),
    pystray.MenuItem("Edit Settings", edit),
    pystray.MenuItem("Github", git),
    pystray.MenuItem("Support", support),
    pystray.MenuItem("Quit", stop)
))

icon.run()

Files: https://i.stack.imgur.com/tORxl.png

I have image.png and tray.py in the same menu but when i run it PIL Image cant find the file heres the error: https://i.stack.imgur.com/XXwIE.png

  • _I have image.png and tray.py in the same menu_ That doesn't matter. It's looking in the **current** directory, which is not necessarily the same. – John Gordon Jul 30 '22 at 01:41
  • @JohnGordon Sorry, i worded that wrong they are both in the same directory – Neon Blade Jul 30 '22 at 01:42
  • I understood what you meant. It does not matter that they are in the same directory. The "current directory" is NOT necessarily the same directory where the python script is located. – John Gordon Jul 30 '22 at 01:43
  • If you need it relative to the file you can do `os.path.join(os.path.dirname(__file__), name)` – Eric Jin Jul 30 '22 at 01:44

0 Answers0