vikingshore vikingshore - 1 year ago 244
Python Question

how do I close window with handle using win32gui in Python

I have obtained the handle of a window I want to target, with win32gui library in Python

How do I close the window?

I have the following code, the second line did what I intended to do

but the last line seems to be wrong.

handle = win32gui.FindWindow(None, r'Notepad++')

I also want to know if I just want to close the window, is the second line necessary?

Besides that, I notice a minor thing, and I am curious about it:

If I try


in Python shell, I get something like:


but if I try

handle = win32gui.CloseWindow(handle)
print handle

then I get


does the 'L' in the end make any difference?

Thanks for your attention!!

Answer Source


import win32con    

This should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download