techlearner
techlearner

Reputation: 1

How to take screenshot using pywinauto in python

Can anyone please help me with python code to capture the attached image:

Upvotes: 0

Views: 3506

Answers (2)

Zhiwei
Zhiwei

Reputation: 64

pip install pywinauto
pip install Pillow

from pywinauto import Desktop, Application
app = Application().start(r'C:\WINDOWS\system32\notepad.exe') 
win = app['UntitledNotepad'] 
win.type_keys('hello world') 
win.capture_as_image().save('screenshot.png')

Upvotes: 1

Sachin
Sachin

Reputation: 171

Try this Code -

import time
from pywinauto.application import Application
from PIL import ImageGrab

# connect to task bar
app = Application().Connect(title=u'', class_name='Shell_TrayWnd')

# Get task bar window
shelltraywnd = app.Shell_TrayWnd

# Get tray clock window
trayclockwclass = shelltraywnd.TrayClockWClass

# Get rectangle of tray clock window
clockRect = trayclockwclass.client_rect()

# Click into the rectangle of tray clock window
trayclockwclass.click_input(coords=(clockRect.left+20, clockRect.bottom-20))

# wait for Clock Flyout to appear
time.sleep(5)

# Grab the top screen
screenBuffer = ImageGrab.grab()

# Save Path/filename
save_path = "yourScreen.jpg"

# Save into file
screenBuffer.save(save_path)

Upvotes: 0

Related Questions