1

I asked an earlier question about how I could detect whether a window was minimized or not and got this code for the answer:

window = win32gui.FindWindow("Notepad", None)
if window:
    tup = win32gui.GetWindowPlacement(window)
    if tup[1] == win32con.SW_SHOWMAXIMIZED:
        minimized = False
    elif tup[1] == win32con.SW_SHOWMINIMIZED:
        minimized = True
    elif tup[1] == win32con.SW_SHOWNORMAL:
        normal = True

As I am sure it works, the problem is that I cannot figure out how to get "win32con" to work. I have tried pip installs, imports, and everything that goes along with it and I still get the error:

NameError: name 'win32con' is not defined

How can I resolve this error and properly import win32con? Thanks.

1 Answers1

1

Took a bit of searching but I have an answer for you.

pip install pypiwin32

I also had to manually type in my imports because my IDE (Pycharm) could not make the link between win32gui and pypiwin32. I've also added some print statements so I could see if it was actually working.

import win32gui
import win32con

window = win32gui.FindWindow("Notepad", None)
if window:
    tup = win32gui.GetWindowPlacement(window)
    if tup[1] == win32con.SW_SHOWMAXIMIZED:
        minimized = False
        print('MAX')
    elif tup[1] == win32con.SW_SHOWMINIMIZED:
        minimized = True
        print('MIN')
    elif tup[1] == win32con.SW_SHOWNORMAL:
        normal = True
        print('NORMAL')
Rusty Robot
  • 1,725
  • 2
  • 13
  • 29