I have done a program with 2 apis that show forecast and city info of diffrent citys that the user choose. But now I need help cause Im stuck on how to get my make_request, make
If you just want to simulate printing to the console, you should use a text widget. The text widget is the right choice for showing multi-line data. Instead of calling print, you call insert:
def create_widgets(self):
...
self.out = Text(self)
...
def make_request(self):
r = requests.get(...)
data = r.json()
self.out.insert("end", data)
...
If you want to show just a few pieces of data, you can use label widgets, and change what appears in them using the config
method. For example:
def create_widgets(self):
...
self.label1 = Label(self, ...)
self.label2 = Label(self, ...)
def make_request(self):
...
self.label1.configure(text=something)
self.label2.configure(text=something_else)
Example - I use existing label with title to set information from request
def make_request(self):
r = requests.get("http://api.wunderground.com/api/61418d709872f773/forecast/q/" + self.enterCountry.get() +"/" + self.v.get() +".json")
data = r.json()
for day in data['forecast']['simpleforecast']['forecastday']:
self.var.set( day['date']['weekday'] + ":" + "\n" + "Conditions: " + day['conditions'] + "\n" + "High: " + day['high']['celsius'] + "C " + "Low: " + day['low']['celsius'] + "C" )
return data