I am attempting to make a simple webview of Google.com using PyWebview that can keep an icon present in the Windows system tray. On clicking the system tray icon, if the webview window is visible, the window will be hidden, and if it is not visible the window will be shown.
The code below is an approximation (apologies, I'm at work and don't have access) of the code I wrote last night. This code ran without error, but clicking the systray icon didn't seem to do anything, as the window was not hidden when visible nor was it shown when it was closed.
I have reviewed similar questions on SO as well as the documentation, but I can't seem to get the window.show/hide to work. Any tips would be greatly appreciated.
import pystray
import webview
from PIL import Image
visible = True
image = Image.open("brain.png")
icon = pystray.Icon
def on_closed():
visible = False
def on_shown():
visible = True
def show_hide_window(window):
if visible == True:
window.hide()
if visible == False:
window.show()
def quit_window(window):
window.destroy()
icon.stop()
icon = pystray.Icon('Google', image, 'Google', menu=pystray.Menu(
pystray.MenuItem('Show/Hide', show_hide_window, default=True),
pystray.MenuItem('Quit', quit_window)))
icon.run_detached()
if __name__ == '__main__':
window = webview.create_window('Google','https://www.google.com')
webview.start(window)
window.events.closed += on_closed
window.events.shown += on_shown