【发布时间】:2019-06-24 00:27:30
【问题描述】:
我正在学习使用类,我想从另一个 MainApplication 类中调用我的 GetWeather 类。
在调用GetWeather.coords 时,我想从一个接收所需数据的函数开始。
以下是我目前的代码:
API_ID = '///foo///'
class GetWeather:
def __init__(self, city, country):
url_city = 'http://api.openweathermap.org/data/2.5/weather?q={},{}&appid={}'.format(city, country, API_ID)
weatherdata = requests.get(url_city).json()
def coords(self):
print(weatherdata)
class MainApplication:
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
self.button1 = tk.Button(self.frame, text = 'Coords', width = 25, command = GetWeather.coords('town','country'))
self.button1.pack()
self.frame.pack()
def main():
root = tk.Tk()
app = MainApplication(root)
root.mainloop()
if __name__ == "__main__":
main()
【问题讨论】:
-
是什么阻碍了你做你想做的事?您需要什么样的帮助?
标签: python python-3.x class tkinter