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

click() 

This method is used to send a virtual mouse click to the computer and by default, it uses the left mouse button.  

Syntax: pyautogui.click()

Parameters: It takes three parameters. x – coordinate, y – coordinate and duration which is optional.

Return type: Doesn’t return anything, simply performs a click.

 For example, pyautogui.click(10, 5, button=’left’) will click the left mouse button at the coordinates (10, 5).

dragRel() 

This method is used to drag the mouse. By dragging, we mean holding the mouse button and dragging the cursor. It also takes 3 arguments; x – coordinate, y – coordinate and button (this is optional).

Syntax: pyautogui.dragRel()

Parameters: It takes three parameters.  x – coordinate, y – coordinate and duration which is optional.

Return type:  Returns nothing, just drags the mouse cursor to the specified location in the form of parameters.

 For example, pyautogui.dragRel(20, 40, 5) will drag the mouse cursor to the specified location in the form of the parameter.

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