【初心者です】お天気アプリにエラーが出てしまいます【Python】
【初心者です】お天気アプリにエラーが出てしまいます【Python】
Pythonアカデミー【エンジニアVthuber凜】様の「Pythonでお天気アプリ作ってみた!!」という動画を基にPythonでお天気アプリを作ったのですが、実装中以下のエラーが発生しました。
URL → https://www.youtube.com/watch?v=I3xCXjpYi0c&t=77s
どなたか解決方法がありましたら教えて頂けると幸いです。
発生している問題・エラー
import tkinter as tk
import requests #お天気APIを取得
#メインウィンドウの作成
canvas=tk.Tk()
canvas.geometry("700*500")
canvas.title("Today's Weather")
a = ("Arialblack",20,"bold") #最低・最高気温を表す文字フォント
b = ("Arialblack",40,"bold") #都市入力・天気の結果を表す文字フォント
#お天気情報を得るためのget_weather関数
def getweather(canvas):
city = textField.get()
api = "https://api.openweathermap.org/data/2.5/weather?q"+"city"+"&appid=" #ここにopenweatherのappidを入れています
json_date = requests.get(api).json()
weather = json_date['weather'][0]['main']
temp = int(json_date['main']['temp'] - 273.15)
min_temp = int(json_date['main']['temp_min'] - 273.15)
max_temp = int(json_date['main']['temp_min'] - 273.15)
#アプリに表示する項目
final_info = weather + "\n"+str(temp)+"℃"
final_date = "\n"+"最低気温:"+str(min_temp)+"℃"+"\n"+"最高気温:"+str(max_temp)+"℃"
label1.config(text=final_info)
label2.config(text=final_date)
#テキストボックス作成
textField = tk.Entry(canvas,justify='center',width=20, font=b)
textField.pack(pady = 30)#pady=外側の縦の隙間
textField.bind('<Return>',getweather) #APIの天気情報を返す
label1 = tk.Label(canvas,font=b)
label1.pack()
label2=tk.Label(canvas,font=a)
label2.pack()
canvas.mainloop()
上記の実装で、以下のエラーコードが出ます。
File"C:\Program Files\Python310\lib\tkiner_init_.py",LIne 1921,in_call_
return self.func(*args)
File"",line 5 ,in getweather
KeyError: 'weather'
NameError (uninitialized constant World)
どなたか解決方法をご存じの方コメントを御願いします。