【发布时间】:2017-10-24 00:36:27
【问题描述】:
首先对不起我的英语不好。
我正在学习 API,我决定在一个非常基本的 KIVY 接口上实现一个天气 API。但是,我无法获得包含天气信息的字典的输出值,作为标签文本。我认为该值不是字符串。你们能帮帮我吗?
class Tempo_Func(BoxLayout):
def tempo(self,cidade):
req=requests.get('http://api.openweathermap.org/data/2.5/weather?q='
+cidade+ '&appid=mykey')
self.tempo = json.loads(req.text)
self.x =(self.tempo['weather'][0]['main'])
class WeatherApp(App):
def build(self):
return Tempo_Func()
if __name__=='__main__':
WeatherApp().run()
千伏
<Tempo_Func>:
orientation:'vertical'
padding:10
spacing:10
BoxLayout:
orientation:'vertical'
Label:
text:"Qual sua cidade?"
size_hint_y:None
TextInput:
id:entry
Button:
text:'Procurar'
on_press:root.tempo(entry.text)
Label:
text:root.x #I want to show the value of self.x here!!
【问题讨论】:
-
什么是回溯?