0
我有一個問題的條目。我希望用戶在
API鏈接中寫任何他們想要的城市。我知道我不能轉換爲str。所以,當過用戶選擇進入一個城市,他只需要點擊按鈕的預測後,他在進入進入城市和天氣將印:API tkinter python條目
from tkinter import *
import requests
import json
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.v = StringVar()
self.e = Entry(self, textvariable=self.v)
self.e.pack(side="left")
self.v.set("Enter City")
self.s = self.v.get()
self.e.focus_set()
self.butn = Button(self)
self.butn["text"] = "Forecast"
self.butn["command"] = self.make_request
self.butn.pack(side="left")
self.QUIT = Button(self, text="QUIT", command=self.root.destroy)
self.QUIT.pack(side="right")
def make_request(self):
r = requests.get("http://api.wunderground.com/api/ab78bcbaca641959/forecast/q/Sweden/" + ???? + ".json")
data = r.json()
for day in data['forecast']['simpleforecast']['forecastday']:
print (day['date']['weekday'] + ":")
print ("Conditions: ", day['conditions'])
print ("High: ", day['high']['celsius'] + "C", "Low: ", day['low']['celsius'] + "C", '\n')
return data
rot = Tk()
rot.geometry("900x650+200+50")
rot.title("The Trip")
app = Application(master=rot)
app.mainloop()