Python 3 Tkinter Script to Display COVID-19 Daily Cases Based on Country GUI Using Pillow Library Desktop App Full Project For Beginners



Welcome folks today in this blog post we will be displaying daily covid-19 cases based on country in python using tkinter framework. All the full source code of the application is shown below.




Get Started




pip install pillow



In order to get started you need to make an file and copy paste the following code



import requests
import tkinter as tk
from PIL import Image, ImageTk
import json 

app = tk.Tk()
app.title('Corona Tracker')
HEIGHT = 500
WIDTH = 600

def format_response(weather_json):
        country = weather_json["data"]['covid19Stats'][0]["country"]
        lastUpdate = weather_json["data"]['covid19Stats'][0]["lastUpdate"]
        confirmed = weather_json["data"]['covid19Stats'][0]["confirmed"]
        deaths = weather_json["data"]['covid19Stats'][0]["deaths"]
        recovered = weather_json["data"]['covid19Stats'][0]["recovered"]
        final_str = 'Country: %s \nLastUpdated: %s \nConfirmed : %s \nDeaths : %s \nRecovered: %s ' % (country,lastUpdate, confirmed,deaths,recovered)
        final_str = 'There was a problem retrieving that information'
    #final_str = 'hello'
    return final_str

def get_details(ans):
    url = "" 
    ans2= ans.capitalize()
    querystring = {"country":ans2,"format":"undefined"}

    headers = {
        'x-rapidapi-host': "",
        'x-rapidapi-key': "d09ecb5585mshbf1cb6dfd23f20cp143727jsn1e892a16518b"

    response = requests.request("GET", url, headers=headers, params=querystring)
    weather_json = response.json()
    results['text'] = format_response(response.json())

C = tk.Canvas(app, height=HEIGHT, width=WIDTH)
background_image= tk.PhotoImage(file='./landscape.png')
background_label = tk.Label(app, image=background_image), y=0, relwidth=1, relheight=1)


frame = tk.Frame(app,  bg='#42c2f4', bd=5), rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')
#frame_window = C.create_window(100, 40, window=frame)

textbox = tk.Entry(frame, font=40), relheight=1)

submit = tk.Button(frame, text='Check', font=40,command=lambda:get_details(textbox.get()) )
#submit.config(font=), relheight=1, relwidth=0.3)

lower_frame = tk.Frame(app, bg='#42c2f4', bd=10), rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')

bg_color = 'white'
results = tk.Label(lower_frame, anchor='nw', justify='left', bd=4)
results.config(font=40, bg=bg_color), relheight=1)

weather_icon = tk.Canvas(results, bg=bg_color, bd=0, highlightthickness=0), rely=0, relwidth=1, relheight=0.5)



See also  Python Tkinter GUI Spinbox Dropdown Widget to Select From Range of Values Full Project For Beginners



Leave a Reply