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:

Square spiral

Python Automation Drawing In Paint Application

In this article, we are going to know how to automate paint applications using Python.

Similar Reads

Introduction

To automate the Paint application in Python, we’ll use a Python library PyAutoGUI which lets the user control keyboard and mouse movements and hence automate interaction with other applications on the system using Python. This library has various methods that will come in handy.  It is used to stimulate mouse cursor moves and keyboard button presses. We can automate several applications using this module. It is mostly used for UI testing. This module has a lot of useful methods that make our tasks easier....

Installation

To install the PyAutoGUI module. Type the following in the command prompt....

We’ll be using two methods of the PyAutoGUI module.

click()...

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....

Example 2:

...

Example 3:

In this example, We are going to automate the drawing of squares in the paint application without using a mouse. we are going to use sleep() method of the time module for delaying the process of drawing squares. After that click() method is used to press click on the canvas of paint and then dragRel() method is used to draw a square....