PyAutoGUI is a python library for GUI automation, and today we are going to perform an automated drawing of a pyramid like above using PyAutoGUI, Lets see how to do that
Before we start , we need to meet some prerequisite
- Install Python visit https://www.python.org/ and download the latest or stable version and install it into your system
- If you are on windows, open command prompt and type
pip install pyautogui– this installs the PyAutoGUI Libs , below shows as requirements satisfied since I already have same installed, you will see the packages downloaded when installed for the first time.

Once we are done with this, open a notepad and save the file as pytestauto.py in your desktop, copy the following code to your file and save
import pyautogui #importing the PyAutoGUI lib
pyautogui.moveTo(50,200) #moving the cursor to the 50,200 position of desktop
pyautogui.click() # click on the position
distance = 200 # setting the distance
while distance > 0:
pyautogui.dragRel(distance, 0, duration=0.5) # move right
distance -= 5
pyautogui.dragRel(0, distance, duration=0.5) # move down
pyautogui.dragRel(-distance, 0, duration=0.5) # move left
distance -= 5
pyautogui.dragRel(0, -distance, duration=0.5) # move up

Open the Python IDLE (start -> search python idle) , open pytestauto.py from the location you have saved the file, click on Run -> Run Module , you will see below

Leave a comment