1) I have a problem with listbox,when user selected one of the country names in the listbox i want it to show the name as entry (default text).
2) after that when i click save button it shows error(actually,I don't know what is about).user could enter the name of the desire country(everything is possible).
3) I have an issue with a line that didn't get it.(i commented it below)
EDIT: 1) After founding my problems,i need to optimize my program.i don't know why it take so much time to get data from the site?
2) I need a label to show output when click on button"Show Data"
Thanks.
from covid import *
from tkinter import *
import tkinter as tk
import matplotlib.pyplot as plt
import pandas as pd
import pickle
import seaborn as sb
def main():
win=Tk()
win.geometry("400x400")
lbl=Label(win,text="Write ur country name:")
lbl.pack()
#print(country_name)
covid=Covid()
#covid_general=Covid(source="worldometers")
in_country=Entry(win)
in_country.pack()
country_name=in_country.get()
def list_country():
lst_country=covid.list_countries()
lbl_countries=Listbox(win,font=("times",14))
lbl_countries.pack(expand=1,fill=BOTH)
for names in lst_country:
lbl_countries.insert(END,names)
'''
for item in name:
in_country.insert(END,lbl_countries.get(item))
print(item)
'''
def save_data():
country=covid.get_status_by_country_name(country_name)
#what does this do?key:country[key]
data={
key:country[key]
for key in country.keys() and {'confirmed','active','deaths','recovered'}
}
#save the data to a file covid.pkl
a_file=open("covid.pkl","wb")
pickle.dump(data,a_file)
a_file.close()
def load_data():
#read the data from covid.pkl
a_file=open("covid.pkl","rb")
output_a=pickle.load(a_file)
#now get data to data frame
df_a=pd.DataFrame(output_a,index=[country_name],columns=['active','deaths','recovered'])
#filter data again with the numbers only.using dataframe
df_b=df_a.loc[country_name]
#check output
print(df_a)
#reforming pieplot
labels = ['active','deaths','recovered']
colors=['orange','red','green']
explode=(0,0.2,0)
#now plot the data
plt.title("Covid Chart")
main_data=plt.pie(df_a,explode=explode,labels=df_b,colors=colors,autopct='%1.1f%%',startangle=140)
plt.legend(labels,loc="upper left")
plt.show()
btn_save=Button(win,text="Save",command=save_data)
btn_load=Button(win,text="load_data",command=load_data)
btn_list=Button(win,text="Show Countries Name",command=list_country)
btn_save.pack()
btn_load.pack()
btn_list.pack()
win.mainloop()
if __name__=="__main__":
main()