How to handle a windows window in python?

Asked

Viewed 815 times

0

Next, I have a very simple code that just opens an exe program

import os caminho = os.startfile(r"C:\Program Files (x86)\Nox\bin\nox.exe")

However, when running, the application window comes minimized and with a very large size, as it could do to decrease the size of the window and not leave it minimized?

1 answer

3


You can use the library pygetwindow. To install it, just type:

Pip install Pygetwindow

For starters, import pygetwindow and then get the window using the function getWindowsWithTitle(title). There are other functions to get a window, but I recommend this, because here you just need to put the window title.

After that, you can use the method resizeTo(newWidth,newHeight) to resize the window and method activate() to make the window appear. See this example below:

import pygetwindow

title = 'Stack Overflow em Português - Google Chrome'

window = pygetwindow.getWindowsWithTitle(title)[0]
window.activate()
window.resizeTo(1280,720)
  • Exactly what I was looking for, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.