Example 1
In this example, We are going to automate the drawing of square spiral in paint application without using mouse. To implement this we are going to use two methods of pyautogui module which are click() and dragRel() that are used inside the while loop to make the square spiral. click() is used to click inside the canvas of paint application and dragRel() is used to move the mouse cursor to make the spiral by incrementing and decrementing the values of parameters of dragRel() method.
Python3
# importing pyautogui import pyautogui pyautogui.click() # initialising a variable distance distance = 200 while (distance): # moves the cursor to the right pyautogui.dragRel(distance, 0 , duration = 0.2 ) distance = distance - 5 # move the cursor down pyautogui.dragRel( 0 , distance, duration = 0.2 ) # move the cursor to the left pyautogui.dragRel( - distance, 0 , duration = 0.2 ) distance = distance - 5 # move the cursor up pyautogui.dragRel( 0 , - distance, duration = 0.2 ) |
Output:
Python Automation Drawing In Paint Application
In this article, we are going to know how to automate paint applications using Python.