how to drag a box on your screen python

Solutions on MaxInterview for how to drag a box on your screen python by the best coders in the world

showing results for - "how to drag a box on your screen python"
Hudson
28 Aug 2017
1import win32gui
2import win32ui
3import win32con
4import win32api
5
6def saveScreenShot(x,y,width,height,path):
7    # grab a handle to the main desktop window
8    hdesktop = win32gui.GetDesktopWindow()
9
10    # create a device context
11    desktop_dc = win32gui.GetWindowDC(hdesktop)
12    img_dc = win32ui.CreateDCFromHandle(desktop_dc)
13
14    # create a memory based device context
15    mem_dc = img_dc.CreateCompatibleDC()
16
17    # create a bitmap object
18    screenshot = win32ui.CreateBitmap()
19    screenshot.CreateCompatibleBitmap(img_dc, width, height)
20    mem_dc.SelectObject(screenshot)
21
22
23    # copy the screen into our memory device context
24    mem_dc.BitBlt((0, 0), (width, height), img_dc, (x, y),win32con.SRCCOPY)
25
26    # save the bitmap to a file
27    screenshot.SaveBitmapFile(mem_dc, path)
28    # free our objects
29    mem_dc.DeleteDC()
30    win32gui.DeleteObject(screenshot.GetHandle())
31