
Today we are going to make Covid-19 Tracker Application Using Python which you can assume to be a medium level project as we will need to use three Python libraries.
Here, we are going to create a GUI application to track the COVID-19 cases.
We need to use three different libraries here.
- tkinter – for GUI
- matplotlib – to show data graphically
- covid – to get COVID data
We have many posts based on tkinter so if you have any problem in tkinter then we suggest to read them.
You can install “matplotlib” using the pip command given below
"pip install matplotlib"
Python community has made a library to get the COVID-19 information easily.
Library is"covid"
and its so simple to use.
Visit this site for more details of this library.
You can download it using the pip command given below.
"pip install covid"
Note: python >= 3.6
Type this command in your terminal to install and use this library.
Now lets see and understand the code.
Code
# importing tkinterfrom tkinter import *# initializing tkinterroot = Tk()# setting geometryroot.geometry("350x350")# setting titleroot.title("Get Covid-19 Data Country Wise")# function which will get covid data and will show itdef showdata():# importing matplotlib which will be used to show data graphicallyfrom matplotlib import pyplot as plt# to scale the data we are importing patchesimport matplotlib.patches as mpatches# importing covid libraryfrom covid import Covid# initializing covid librarycovid = Covid()# declaring empty lists to store different data setscases = []confirmed = []active = []deaths = []recovered = []# using try and except to run program without errorstry:# updating rootroot.update()# getting countries names entered by the usercountries = data.get()# removing white spaces from the start and end of the stringcountry_names = countries.strip()# replacing white spaces with commas inside the stringcountry_names = country_names.replace(" ", ",")# splitting the string to store names of countries# as a listcountry_names = country_names.split(",")# for loop to get all countries datafor x in country_names:# appending countries data one-by-one in cases list# here, the data will be stored as a dictionary# for one country i.e. for each country# there will be one dictionary in the list# which will contain the whole information# of that countrycases.append(covid.get_status_by_country_name(x))# updating the rootroot.update()# for loop to get one country data stored as dict in list casesfor y in cases:# storing every Country's confirmed cases in the confirmed listconfirmed.append(y["confirmed"])# storing every Country's active cases in the active listactive.append(y["active"])# storing every Country's deaths cases in the deaths listdeaths.append(y["deaths"])# storing every Country's recovered cases in the recovered listrecovered.append(y["recovered"])# marking the color information on scaleusing patchesconfirmed_patch = mpatches.Patch(color='green', label='confirmed')recovered_patch = mpatches.Patch(color='red', label='recovered')active_patch = mpatches.Patch(color='blue', label='active')deaths_patch = mpatches.Patch(color='black', label='deaths')# plotting the scale on graph using legend()plt.legend(handles=[confirmed_patch, recovered_patch, active_patch, deaths_patch])# showing the data using graphs# this whole for loop section is related to matplotlibfor x in range(len(country_names)):plt.bar(country_names[x], confirmed[x], color='green')if recovered[x] > active[x]:plt.bar(country_names[x], recovered[x], color='red')plt.bar(country_names[x], active[x], color='blue')else:plt.bar(country_names[x], active[x], color='blue')plt.bar(country_names[x], recovered[x], color='red')plt.bar(country_names[x], deaths[x], color='black')# setting the title of the graphplt.title('Current Covid Cases')# giving label to x direction of graphplt.xlabel('Country Name')# giving label to y direction of graphplt.ylabel('Cases(in millions)')# showing the full graphplt.show()except Exception as e:# asking user to enter correct details# during entering the country names on GUI# please differentiate the country names# with spaces or comma but not with both# otherwise you will come to this sectiondata.set("Enter correct details again")Label(root, text="Enter all countries names\nfor whom you want to get\ncovid-19 data", font="Consolas 15 bold").pack()Label(root, text="Enter country name:").pack()data = StringVar()data.set("Seperate country names using comma or space(not both)")entry = Entry(root, textvariable=data, width=50).pack()Button(root, text="Get Data", command=showdata).pack()root.mainloop()
Also Read:
- Auto Login with Python
- Adding three matrices in Python
- Simple Music Player Using Python
- Changing Screen Size: Tkinter
- GUI Age Calculator
- Displaying Images in tkinter
- Creating User-defined Entry Widgets
- Password Generator GUI Application In Python
- GUI Calculator Using Tkinter In Python
- Simple Text To Speech In Python
- How to Get WiFi Passwords With Python?
- Crack Any Password Using Python
- Tkinter Login GUI with hiding password
- Get IP address using Python
- See wifi password using Cmd
- URL Shortener Using Python
- GUI Application To See wifi password in Python
- Python Tuples
- Calendar using Python
- YouTube Video Downloader Using Python
- Python Booleans
- Download YouTube Video Using Python
- Binary Search In Python
- URL Opening Application Using Python
- Get COVID Information Using Python
- Covid-19 Tracker Application Using Python
- Snake Game in Python using Pygame
- Event Handling In Tkinter Python
- Classical Newspaper Using Tkinter Python
- Calculator Program In Python