How to make my window on top after window.show()? #1366
Replies: 4 comments 2 replies
-
I’ve discovered a very strange phenomenon. In fact, I wanted to minimize the program to the taskbar using pystray, which led to this issue. Currently, if I right-click the taskbar icon and click “Open,” then hide the window, cycling back and forth like this, the window consistently alternates between being on top and being obscured by other windows. However, if I directly left-click the taskbar icon (since default=True is set, a left-click is equivalent to a right-click followed by clicking Open—or so I thought), then subsequent opened windows will always be on top, except for the first time they are obscured. """
Run pywebview alongside with pystray to display a system tray icon.
"""
from threading import Thread
from PIL import Image
from pystray import Icon, Menu, MenuItem
import webview
if __name__ == '__main__':
def on_open(icon, item):
window.show()
def on_exit(icon, item):
icon.stop()
window.destroy() # can not completely exit
def on_closing():
t = Thread(target=window.hide)
t.start()
return False
image = Image.open('logo/logo.png')
menu = Menu(MenuItem('Open', on_open, default=True), MenuItem('Exit', on_exit))
icon = Icon('Pystray', image, menu=menu)
Thread(target=icon.run, daemon=True).start()
window = webview.create_window('Webview', 'https://pywebview.flowrl.com/hello')
window.events.closing += on_closing
webview.start() |
Beta Was this translation helpful? Give feedback.
-
Hi, Aues6uen11Z, For the exit problem, i.e. the main thread do not exit after running the """
Run pywebview alongside with pystray to display a system tray icon.
"""
from threading import Thread
from PIL import Image
from pystray import Icon, Menu, MenuItem
import webview
# use signal to pass EXIT command
SIGNAL = {'on_running' : True}
if __name__ == '__main__':
def on_open(icon, item):
window.show()
def on_exit(icon, item):
icon.stop()
# emit exit signal
SIGNAL['on_running']= False
window.destroy() # can not completely exit
def on_closing():
t = Thread(target=window.hide)
t.start()
# use signal to exit window
return not SIGNAL['on_running']
image = Image.open('logo/logo.png')
menu = Menu(MenuItem('Open', on_open, default=True),
MenuItem('Exit', on_exit))
icon = Icon('Pystray', image, menu=menu)
Thread(target=icon.run, daemon=True).start()
window = webview.create_window('Webview', 'https://pywebview.flowrl.com/hello')
window.events.closing += on_closing
webview.start() |
Beta Was this translation helpful? Give feedback.
-
Found a solution :) try:
except Exception as e: |
Beta Was this translation helpful? Give feedback.
-
I pushed a fix for this to master. Now window is activated when shown. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone, I’ve found that in the Windows system, when a window is displayed by calling
window.show()
from a hidden state, it does not become the focus. If there is another window in the focus state, the pywebview window will be obscured by that window. Here is an example:I’m not sure what the reasoning behind this is, but I would like my program to be on top and in focus every time it is displayed. Can someone help me? I would be very grateful.
Beta Was this translation helpful? Give feedback.
All reactions