# Maximize a window in Windows - Python
Data Science for Political and Social Phenomena
Author: Guillaume Redoulès

# Maximize a window in Windows

A window can be maximized by using the win32 API. We will need to import `win32gui` and `win32con`

    import win32gui
    import win32con

In order to maximize a windows, we need its handle number. In our example we will get the handle of the foreground window by using the GetForegroundWindow method.

    handle = win32gui.GetForegroundWindow()

The window can then be maximized with the command

    win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)

    24

minimized with the command

    win32gui.ShowWindow(handle, win32con.SW_MINIMIZE)

    24

or restored to its original size with the command

    win32gui.ShowWindow(handle, win32con.SW_NORMAL)

    24

The win32 API allow to hide or show a window.

    import time

    win32gui.ShowWindow(handle, win32con.SW_HIDE) #hide the window
    time.sleep(1) #keep it hidden for a second
    win32gui.ShowWindow(handle, win32con.SW_SHOW) #show the window

    0

### Find an error or bug? Have a suggestion?

Everything on this site is avaliable on GitHub. Head on over and submit an issue. You can also message me directly by email.