Welcome back to another tutorial, today I will be showing you how to install modules and add more functionality to your script.

 

To start, make a new file and import the following

import os

import sys

import time

Once you’ve done that we’re going to install a module called “pyautogui” which allows for simple interfaces as well as mouse and keyboard input.

 

To install it click the “terminal” button near the bottom of pycharm. once you’ve clicked it, it should look something like this

Python Tutorial 4 - Installing Modules 1

 

Once you have the terminal open type the following into the console

pip3 install pyautogui

it should start downloading, let it run as it may take some time.

 

after it’s finished installing add the following to the beginning of the file.

import pyautogui

Once you’ve imported pyautogui, we’re going to make a simple program that tells you where the cursor is on the screen.

 

To start I recommend adding the following to the file

time.sleep(10)

This will be more useful once we start making more advanced programs using pyautogui, for now, it just allows you to move the mouse before the actual code runs. Now onto the code that outputs the position of the mouse. Add the following to your code.

print(pyautogui.position())

Now when you run the code it should output the X and Y coordinates of the cursor on your screen.

 

In the next tutorial, I will be showing you how to output that to a dialog box.

 

Previous Tutorial

 

Leave a Reply