Covid-19 Tracker Application Using Python

Covid-19 Tracker Application Using Python

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.

  1. tkinter – for GUI
  2. matplotlib – to show data graphically
  3. 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"

assignment advertisement

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 tkinter
from tkinter import *
# initializing tkinter
root = Tk()
# setting geometry
root.geometry("350x350")
# setting title
root.title("Get Covid-19 Data Country Wise")

# function which will get covid data and will show it
def showdata():
    # importing matplotlib which will be used to show data graphically
    from matplotlib import pyplot as plt
    # to scale the data we are importing patches
    import matplotlib.patches as mpatches
    # importing covid library
    from covid import Covid
    # initializing covid library
    covid = Covid()
    # declaring empty lists to store different data sets
    cases = []
    confirmed = []
    active = []
    deaths = []
    recovered = []
    # using try and except to run program without errors
    try:
        # updating root
        root.update()
        # getting countries names entered by the user
        countries = data.get()
        # removing white spaces from the start and end of the string
        country_names = countries.strip()
        # replacing white spaces with commas inside the string
        country_names = country_names.replace(" ", ",")
        # splitting the string to store names of countries
        # as a list 
        country_names = country_names.split(",")
        # for loop to get all countries data
        for 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 country
            cases.append(covid.get_status_by_country_name(x))
            # updating the root
            root.update()
        # for loop to get one country data stored as dict in list cases
        for y in cases:
            # storing every Country's confirmed cases in the confirmed list
            confirmed.append(y["confirmed"])
            # storing every Country's active cases in the active list
            active.append(y["active"])
            # storing every Country's deaths cases in the deaths list
            deaths.append(y["deaths"])
            # storing every Country's recovered cases in the recovered list
            recovered.append(y["recovered"])
        # marking the color information on scaleusing patches
        confirmed_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 matplotlib
        for 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 graph
        plt.title('Current Covid Cases')
        # giving label to x direction of graph
        plt.xlabel('Country Name')
        # giving label to y direction of graph
        plt.ylabel('Cases(in millions)')
        # showing the full graph
        plt.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 section
        data.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()



This is just a simple application but you can make this more interesting and more user friendly.

Don’t forget to turn on your data during the running of this program.



If you have any doubt then you can comment below or contact us.

This is the GUI version and if you want a simple program then click here.

Thank you


Also Read:

  • Auto Login with Python
    So today we will learn how to auto login in a tab using Python. So, let’s first see the code, and then we will understand the code through comments. Code Thanks for visiting the site Keep in touch with our site for more amazing material like this Also read:
  • Adding three matrices
    In python, it’s very easy to deal with matrices due to its simple syntax and we create matrices using nested lists in python. We simply create matrices by creating lists inside lists as follows matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] As you can see we created lists inside a list…
  • Simple Music Player Using Python
    Hello friends, do you know that there are many ways to make music players from simple to advanced level. Here, we are presenting you with two very very basic music player in python. One of them is a simple program and the other one is the GUI program. For the simple program, we have used…
  • Changing Screen Size: Tkinter
    Hello guys welcome again to our site where you get amazing source code absolutely free with explanation So, today’s topic is to change the screen size from the screen by itself by taking the arguments for width and height To change the screen size we have set two entry widgets in front of width and…
  • GUI Age Calculator
    Hello friends, today we will make an age calculator using python’s GUI library tkinter so, let’s start. Python offers a very good GUI library i.e. tkinter which is very easy to learn and use. Here, we are creating a GUI application to calculate age using a button. We will ask the user to enter the…
  • Displaying Images in tkinter
    Hello guys, as usual we are sharing one more source code using which you can display images inside your GUI screen of tkinter We will restrict ourselves to .png format only. For .jpg format, we have given an example as comments Tkinter GUI is a python library which is designed in such a way that…
  • Rock Paper Scissor Game Using Python Tkinter
    Most of us have played this game of Rock Paper Scissor and today we will make this Rock Paper Scissor Game Using Python Tkinter. We will be using the random module which will be used here for the purpose of generating a random choice so that we can present it as a guess by the…


Share:
Avatar of Harry

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you

22 thoughts on “Covid-19 Tracker Application Using Python

  1. after running , it is showing DLL load failed while importing ft2font : the speific module could not be found . pls help me to fix this

  2. from covid import covid
    covid=covid()
    case=covid.get_status_by_country_name(“india,!”)
    for x in cases:
    print(x, “:!”,cases[x])

  3. from covid import covid
    covid=covid()
    case=covid.get_status_by_country_name("india,!") 
    for x in cases:
               print(x, ":!",cases[x])

    1. You have the wrong indentation in the last line, indentation is generally equaled to four white spaces while your code has 11 spaces.

  4. It take only two input to show the graph
    What to do if we want to take 4 to 5 countries?

  5. From covid import Covid
    ImportError:cannot import name Covid
    From partially initialized module covid
    I am getting this error in covid tracker
    Project

    1. For that error u need to install the dependencies:

      pip install pydantic
      pip install requests

      and later the module:

      pip install covid

  6. Sir plz help me.. When I press the show data button… Every time it shows enter correct details…..why it doesn’t show me a data.

  7. Traceback (most recent call last):
    File “C:\Apps\Python\lib\tkinter\__init__.py”, line 1883, in __call__
    return self.func(*args)
    File “C:/Users/admin/Desktop\covid.py”, line 17, in showdata
    from covid import Covid
    ImportError: cannot import name ‘Covid’ from partially initialized module ‘covid’ (most likely due to a circular import) (C:/Users/admin/Desktop\covid.py)

    I am getting this error can you help me to solve this ?

Comments are closed.