-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window.activate() not working in Jupyter Notebook #16
Comments
I'm seeing the same thing in Windows simply trying to connect to a Notepad window. I'm using click on the window to achieve an activation instead fw = pyautogui.getWindowsWithTitle('Notepad')
fw = fw[0]
fw.maximize()
pyautogui.click(fw.center); pyautogui.write('abc', 0.01) |
Hello guys, I have encountered the same issue and I'm sorry if my anwser/workaround looks novice but thats what I am so yeah. Searching for the reason why this happens I fell down the rabbit whole but I think I some what have an anwser but unfortunately I did not find the sollution.
It now seems to bee connected to the procces. after a function like this it seems that the .activate() function seems to work perfectly fine since its pointed to that procces. Until it is minimized because there in no window to focus on. I have tested it with multiple windows of notepad and looks like it keeps connected to one specific window since "its pointed" to there to bring it to the foreground. Hopefully I can find the precise reason and get a fully working sollution instead of a workaround cheers |
I use the following workaround: <import` pygetwindow, mouse def activate(win): type(win) |
Please try run Application with administrator privileges in Windows10. |
I'm not pretty sure why this happens, but I also have a workaround that may look cleaner:
What we do here is try to activate the desired window, then, if this fails, minimize and maximize the same window. No need to import extra libraries or complicated procedures. |
This works great! the only thing I'd add is that I also used hwnd[0].restore() at the end, because my program isn't maximized. So now it works great! |
What worked for me was:
The trick was the |
This actually works, Thanks Man |
It worked. thanks |
This didn't work for me as written but it got me over the hump and yours lead to what I think is the most elegant solution. You don't need to minimize, maximize, check if activated. You just need to click() and activate(). import pygetwindow as gw for window in gw.getWindowsWithTitle(''): Many thanks |
window.minimize() window.minimize() is used to minimize the specified window, hiding it in the taskbar or system tray. |
LLego años tarde y en español pero esto funciono para mi import win32gui, win32com.client |
Works fine in a
cmd
but when I run it on a Jupyter Notebook (Colab local runtime):VSCode flashes on the taskbar but never activated.
Strangely if I focus the window first with
pywinauto
:then it would work normally, until I restarted the notebook. This only affects one window, other windows have to be focused with
pywinauto
before being able to be activated withpygetwindow
.Kernel output:
The text was updated successfully, but these errors were encountered: