1

I´ve built a simple GUI app, and I´m playing with pystray. Actually, my script starts as usual, the first thing you see is the GUI. If you klick on exit, the GUI minimize, and the tray Icon spawns.

For now, i search a way to start my script in this "tray Mode" here are some informations:

class Hauptfenster:

    # Define a function for quit the window
    def quit_window(icon, item):
        icon.stop()
        fenster.destroy()

    # Define a function to show the window again
    def show_window(icon, item):
        icon.stop()
        fenster.after(0, fenster.deiconify())

    # Hide the window and show on the system taskbar
    @staticmethod
    def hide_window():
        fenster.withdraw()
        image = Image.open(os.path.join(application_path, iconFile))
        menu = (item('Beenden', Frontend.Hauptfenster.quit_window), item('Einstellungen', Frontend.Hauptfenster.show_window))
        icon = pystray.Icon("name", image, "Quicksafe", menu)
        icon.run()

Please ask me if you need some more Information and Thanks a lot ! Best regards

Background: My programm should lay in the autostart of win10 , but i dont want to minimize the window each time i restart my pc

iWischMob
  • 49
  • 6
  • [Are you looking for this?](https://stackoverflow.com/a/54841035/13629335) – Thingamabobs Nov 14 '21 at 16:14
  • @Atlas435Not at all... pystray works fine... but i want to start my programm in this "Tray Mode" from theb beginning – iWischMob Nov 14 '21 at 16:49
  • since I dont use this modul I cant provide code. But Im not quit sure why it shouldnt be possible to call the functions you like in the `__init__` section of your code, that will be executed as soon as you run this code. What am I missing ? – Thingamabobs Nov 14 '21 at 18:13
  • @iWischMob You might want to use pythonw.exe. Not sure tho, but for further information, read [this](https://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe/30313091) – Itsjul1an Nov 14 '21 at 19:22

1 Answers1

2

I just added my method hide_window to my main function, when script starts, you see something moving on to screen for 2ms.. but it disapears very quick... so thats something I can live with

iWischMob
  • 49
  • 6