pywin32 Windows Extensions for Python 1
Python 2018. 11. 27. 08:58 |반응형
Python에서 windows API를 사용 할 수 있게 해 주는 모듈이다.
간단한 Desktop GUI 예제:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import win32api import win32gui import win32con import win32ui hWnd = win32gui.GetDesktopWindow() # Retrieves a handle to the desktop window. The desktop window covers the entire screen. # The desktop window is the area on top of which other windows are painted. hdc = win32gui.GetDC(hWnd) #win32gui.GetDC(None) # A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC # retrieves the DC for the entire screen. red = win32api.RGB(255, 0, 0) win32gui.SetPixel(hdc, 0, 0, red) # (0, 0)에 빨간 점 그리기 MyPen = win32gui.CreatePen(win32con.PS_SOLID, 5, win32api.RGB(0,0,255)); OldPen = win32gui.SelectObject(hdc, MyPen); win32gui.Rectangle(hdc, 50, 50, 100, 100) # (50, 50, 100, 100)에 파란 선으로 사각형 그리기 win32gui.SelectObject(hdc, OldPen); win32gui.DeleteObject(MyPen); # 폰트 만들기 font_spec = {'name':'Arial', 'height':42, 'weight':30} font = win32ui.CreateFont(font_spec) #lf = win32gui.LOGFONT() #lf.lfFaceName = "Times New Roman" #lf.lfHeight = 100 #lf.lfWeight = win32con.FW_NORMAL #hf = win32gui.CreateFontIndirect(lf) oldfont = win32gui.SelectObject(hdc, font.GetSafeHandle()) win32gui.SetTextColor(hdc, win32api.RGB(255,0,0)) win32gui.SetBkColor(hdc, win32api.RGB(255,255,0)) #win32gui.SetBkMode(hdc, win32con.TRANSPARENT) # Desktop window DC로는 SetBKMode()가 잘 작동하지 않는다 text = 'Software Engineer' rect = win32gui.GetClientRect(hWnd) win32gui.DrawText(hdc, text, len(text), rect, win32con.DT_CENTER | win32con.DT_VCENTER | win32con.DT_SINGLELINE | win32con.DT_WORDBREAK) # 화면 가운데 문자열 출력 win32gui.SelectObject(hdc,oldfont) win32gui.DeleteObject(font.GetSafeHandle()) win32gui.ReleaseDC(hWnd, hdc) | cs |
반응형
'Python' 카테고리의 다른 글
Pillow 이미지 서치(Image Search) 1 (0) | 2018.11.30 |
---|---|
pywin32 Windows Extensions for Python 2 (0) | 2018.11.27 |
Pillow 화면 변화 감지(Pixel Checksum) 2 (0) | 2018.11.21 |
Pillow 화면 변화 감지(Pixel Checksum) 1 (0) | 2018.11.20 |
PyMySQL (2) | 2018.11.19 |