Author - StudySection Post Views - 2,782 views
ss

Automate Calculator using Python

In this tutorial, you will learn how to automate the calculator of your operating system whether it is Linux or any other operating system. We are going to use a python library pyautogui which is a cross platform library. It means we can write code only once and can run that on macOS, Windows, and Linux. Let’s get started with the interesting part that is automating the calculator.

Step 1: Firstly make sure that you have python installed in your system. Then install pyautogui by following the guide in this link.

Step 2: Create a file with the name test.py and paste the below code. You can change the opening calculator code according to your operating system. I am using Ubuntu to make it work.

import time
import pyautogui as pag
#Below code will open the calculator.
pag.press("winleft", _pause=True) #will trigger left window key to open the start menu
time.sleep(0.5)
pag.typewrite("calculator",interval=0.2) # it will type calculator in the search.
time.sleep(0.5)
pag.press("enter") # it will trigger the enter key to open the calculator.
time.sleep(0.5)
#Below code will perform add operation on the calculator.
pag.press("2")
time.sleep(0.5)
pag.press("+")
time.sleep(0.5)
pag.press("5")
time.sleep(0.5)
pag.press("+")
time.sleep(0.5)
pag.press("9")
time.sleep(0.5)
pag.press("enter")
time.sleep(0.5)
pag.press("esc")
#Below code will perform subtraction operation on the calculator.
pag.press("9")
time.sleep(0.5)
pag.press("-")
time.sleep(0.5)
pag.press("2")
time.sleep(0.5)
pag.press("-")
time.sleep(0.5)
pag.press("6")
time.sleep(0.5)
pag.press("enter")
time.sleep(0.5)
pag.press("esc")
#Below code will perform a multiplication operation on the calculator.
pag.press("2")
time.sleep(0.5)
pag.press("*")
time.sleep(0.5)
pag.press("2")
time.sleep(0.5)
pag.press("*")
time.sleep(0.5)
pag.press("6")
time.sleep(0.5)
pag.press("enter")
time.sleep(0.5)

Step 3: Now run the code by running the following command in the terminal.

python path-to-the-file/test.py

After running the above command, your calculator is opened automatically and all operations are performed by python.

Automate Calculator

It was a simple tutorial to automate the calculator. You can make it more advanced according to your requirements.

Knowledge of .NET is quite rewarding in the IT industry. If you have got some skills in the .NET framework then a .NET Certification from StudySection can prove to be a good attachment with your resume. You can go for a foundation level certificate as well as an advanced level certificate in the .NET framework.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri