0

I'm in a pretty sticky situation... I've made an application on python, and then have SysTrayIcon to add a tray item for a user to easily show/hide/close the app.

Unfortunately, the quit method doesn't close my app at all, it just deletes the tray icon previously created...

What I'd like it to do is close the main application window and the tray icon at the same time.

For this effect, I've already tried calling os.system("TASKKILL /F /IM py.exe") (the cmd window launched from the running application). This didn't work. I tried the similar:

for process in (process for process in psutil.process_iter() if process.name()=="py.exe"):
    process.kill()

to no avail.

I also tried sys.exit(), but that just closes the Tray Icon system of course, not the cmd process.

I've sort of run out of ideas, so I'd greatly appreciate it if anyone has additional tips or ideas to fix this.

Feel free to ask if I've left out some info for good understanding of the issue.

Overview of the issue

Angaros
  • 1
  • 1
  • 1
    do you _need_ this cmd window? because you could run your program with pythonw (no console) – Jean-François Fabre Mar 13 '21 at 22:30
  • problem is your architecture. Your taskkill / psutil loops kill _every_ app that use `py.exe`, so that's bad, and probably kill your own systray in the process (that can be solved by filtering out your own pid though) – Jean-François Fabre Mar 13 '21 at 22:32
  • Hey! How can I launch the program with pythonw? Since the code runs from a compiled .exe file, I'm not sure how to do that. On that second point, I don't mind if systray dies at the same time, since I don't want the systray running if the app is closed in any case. All I want is for the quit button to stop everything related to the app, aka 3 components: the cmd window, the app itself if it is open, and the systray. – Angaros Mar 14 '21 at 13:17
  • why don't you create the systray icon _in the same process_ as your python app? that would be the most logical choice – Jean-François Fabre Mar 14 '21 at 14:22
  • I see... You're right. I'll try that and come back to you if it still isn't fixed. Thanks for your help – Angaros Mar 15 '21 at 06:51

0 Answers0