r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.68k stars 547 forks source link

How do i get the window handle? #1482

Open Olypolyu opened 1 week ago

Olypolyu commented 1 week ago

Specification

Description

I'm trying to build an app that adds a overlay and for that i want for the window to pop up when a key combo is pressed and for it to assume focus. This probably should just be a part of pywebview itself, but just giving me the window handle so i can control the window with pywin32 is enough.

Practicalities

r0x0r commented 6 days ago

You can use something like after a window is created (e.g. in the shown event handler) window.gui.BrowserView.instances['master'].Handle

This will get hwnd for the main window. For other windows instance id will be something else.

I have been thinking about exposing a native window instance to the window object, so getting handler could be for example window.native_window.Handle. Will try to add at some point.