我正在尝试使用 Tkinter 使用天气 GUI 并且我正在关注教程@ https://www.youtube.com/watch?v=D8-snVfekto&t=3227s我正在尝试添加我自己的类而不是使用更多代码.我不断收到错误消息,说明weather is not defined我得到了什么,但是我如何安排我的函数和类以便能够使用我的类和打印return str(name) +' ' + str(description) +' '+ str(tempOverall)?我试图重新排列代码以运行该get_weather()函数,但随后我必须运行并调用我还不知道的城市名称,直到用户输入城市名称。这是我的课...class temperature(): def __init__(self): super(temperature, self).__init__() self.tempOverall = (weather['main']['temp']) self.tempMin = (weather['main']['temp_min']) self.tempMax = (weather['main']['temp_min'])temp = temperature()这是我创建响应的地方...def formatResponse(weather): name = (weather ["name"]) description = (weather['weather'][0]['description']) return str(name) +' ' + str(description) +' '+ str(tempOverall)最后,这是我使用 API 的地方...def get_weather(city): wether_key = "22c2d09d0eb26074b8c8b4a293f72682" url = "https://api.openweathermap.org/data/2.5/weather" params= {'APPID': wether_key, 'q': city, 'units': 'imperial'} response = requests.get(url, params=params) weather = response.json() label['text'] = formatResponse(weather)
添加回答
举报
0/150
提交
取消