I created a python script that whenever is run creates a tray at the bottom right on Windows 11.
some code
...
image = PIL.Image.open(r"D:\payDisplay\images\pound_icon.png")
icon = pystray.Icon("Pay", image, menu=pystray.Menu(
pystray.MenuItem("Update", on_clicked)
))
on_clicked(icon)
log.write(f'Finished timetables sorting.\n')
log.close()
icon.run()
I want this script to be launched on backgroud whenever I log into windows. But here is the problem: If I run the script from cmd - tray appears and everything works. If it is run by the task scheduler, the process is running in the background but tray does not appear, all the code before icon.run() executes but I think windows just freezes or kills the process when it encounters icon.run().
It doesn't give any errors. I tried to wrap every line in the code above with try .. except block and print to the log whenever there is an exception but no errors have been logged.
NOTE: I am using these options in task scheduler: Program/script: C:\Users\yagni\AppData\Local\Programs\Python\Python311\pythonw.exe Add arguments: taskbarPay.pyw Start in: D:\payDisplay