Python

Python으로 Window 제어하기 (PyWinAuto)

Alone Life 2021. 4. 5. 21:08
728x90

GitHub : github.com/pywinauto/pywinauto

 

pywinauto/pywinauto

Windows GUI Automation with Python (based on text properties) - pywinauto/pywinauto

github.com

 

Doc : pywinauto.readthedocs.io/en/latest/

 

What is pywinauto — pywinauto 0.6.8 documentation

© Copyright 2018, Mark Mc Mahon and Contributors Revision aea0429b.

pywinauto.readthedocs.io

설치

> pip install pywinauto

 

사용 방법

 

프로그램 실행 

from pywinauto.application import Application
app = Application(backend="uid").start("notepad.exe")

backend = uid 또는 win32

start = 실행할 프로그램 경로

 

이미 실행되어 있는 프로그램 연결

app = Application(backend='win32').connect(title_re="프로그램 제목", class_name="프로그램의 클래스")

Spy++ 을 사용하여 프로그램의 자세한 내용은 확인할 수 있다.

자세한 내용은 아래 원문 설명이 있다.

 

pywinauto.readthedocs.io/en/latest/getting_started.html

 

Getting Started Guide — pywinauto 0.6.8 documentation

Once you have installed pywinauto - how do you get going? The very first necessary thing is to determine which accessibility technology (pywinauto’s backend) could be used for your application. AT SPI on Linux and Apple Accessibility API are in the long

pywinauto.readthedocs.io

앱 하위의 위젯을 찾는 방법

dlg = app.Notepad # 위젯의 이름

dlg = app['Notepad'] # 위젯의 이름

 

다이얼로그의 하위 위젯을 보는 방법

app.YourDialog.print_control_identifiers() # 자식 위젯을 보여준다.

출력 예시

Button - Paper   (L1075, T394, R1411, B485)
        'PaperGroupBox' 'Paper' 'GroupBox'
Static - Si&ze:   (L1087, T420, R1141, B433)
        'SizeStatic' 'Static' 'Size'
ComboBox -    (L1159, T418, R1399, B439)
        'ComboBox' 'SizeComboBox'
Static - &Source:   (L1087, T454, R1141, B467)
        'Source' 'Static' 'SourceStatic'
ComboBox -    (L1159, T449, R1399, B470)
        'ComboBox' 'SourceComboBox'
Button - Orientation   (L1075, T493, R1171, B584)
        'GroupBox' 'Orientation' 'OrientationGroupBox'
Button - P&ortrait   (L1087, T514, R1165, B534)
        'Portrait' 'RadioButton' 'PortraitRadioButton'
Button - L&andscape   (L1087, T548, R1165, B568)
        'RadioButton' 'LandscapeRadioButton' 'Landscape'
Button - Margins (inches)   (L1183, T493, R1411, B584)
        'Marginsinches' 'MarginsinchesGroupBox' 'GroupBox'
Static - &Left:   (L1195, T519, R1243, B532)
        'LeftStatic' 'Static' 'Left'
Edit -    (L1243, T514, R1285, B534)
        'Edit' 'LeftEdit'
Static - &Right:   (L1309, T519, R1357, B532)
        'Right' 'Static' 'RightStatic'
Edit -    (L1357, T514, R1399, B534)
        'Edit' 'RightEdit'
Static - &Top:   (L1195, T550, R1243, B563)
        'Top' 'Static' 'TopStatic'
Edit -    (L1243, T548, R1285, B568)
        'Edit' 'TopEdit'
Static - &Bottom:   (L1309, T550, R1357, B563)
        'BottomStatic' 'Static' 'Bottom'
Edit -    (L1357, T548, R1399, B568)
        'Edit' 'BottomEdit'
Static - &Header:   (L1075, T600, R1119, B613)
        'Header' 'Static' 'HeaderStatic'
Edit -    (L1147, T599, R1408, B619)
        'Edit' 'TopEdit'
Static - &Footer:   (L1075, T631, R1119, B644)
        'FooterStatic' 'Static' 'Footer'
Edit -    (L1147, T630, R1408, B650)
        'Edit' 'FooterEdit'
Button - OK   (L1348, T664, R1423, B687)
        'Button' 'OK' 'OKButton'
Button - Cancel   (L1429, T664, R1504, B687)
        'Cancel' 'Button' 'CancelButton'
Button - &Printer...   (L1510, T664, R1585, B687)
        'Button' 'Printer' 'PrinterButton'
Button - Preview   (L1423, T394, R1585, B651)
        'Preview' 'GroupBox' 'PreviewGroupBox'
Static -    (L1458, T456, R1549, B586)
        'PreviewStatic' 'Static'
Static -    (L1549, T464, R1557, B594)
        'PreviewStatic' 'Static'
Static -    (L1466, T586, R1557, B594)
        'Static' 'BottomStatic'

 

pywinauto.readthedocs.io/en/latest/HowTo.html

 

How To’s — pywinauto 0.6.8 documentation

The windows handle of a window of the application, e.g. app = Application().connect(handle=0x010f0c)

pywinauto.readthedocs.io

키 입력하는 방법

app.Properties.OKButton.click() # 버튼 클릭 이벤트 보내기

# 키보드 입력 방법
app['Dialog']['Edit'].type_keys('Sample')
app['Dialog']['Edit'].type_keys('{VK_RIGHT}{BACKSPACE}')

pywinauto.readthedocs.io/en/latest/getting_started.html

 

Getting Started Guide — pywinauto 0.6.8 documentation

Once you have installed pywinauto - how do you get going? The very first necessary thing is to determine which accessibility technology (pywinauto’s backend) could be used for your application. AT SPI on Linux and Apple Accessibility API are in the long

pywinauto.readthedocs.io

 

KeyCode : pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html

 

pywinauto.keyboard — pywinauto 0.6.8 documentation

© Copyright 2018, Mark Mc Mahon and Contributors Revision aea0429b.

pywinauto.readthedocs.io

 

반응형