2017-05-23 4 views
0

처음 영어 실력을 못 미안합니다.Kivy label.text에 출력 dict 값

API에 대해 배우고 있으며 매우 기본적인 KIVY 인터페이스에 날씨 API를 구현하기로 결정했습니다. 그러나 Im은 날씨 정보를 포함하는 Dict의 출력 값을 레이블 텍스트로 가져올 수 없습니다. 나는 그 값이 문자열이 아니라고 생각한다. 니들 도와 줄래?

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() 

KV

<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!! 
+0

추적 표시 란 무엇입니까? – Kanak

답변

0

변경이로 .kv 파일 :

<Tempo_Func>: 
    orientation: 'vertical' 
    padding: 10 
    spacing: 10 
    Label: 
     text: "Qual sua cidade?" 
     size_hint_y: None 
    TextInput: 
     id: entry 
    Button: 
     text: 'Procurar' 
     on_press: root.tempo(entry.text) 
    Label: 
     text: str(root.x) 

이 작동하는 것 같다. API 키가 없기 때문에 오류가 발생하므로 직접 확인해야합니다.

+0

대단히 감사합니다! 작동했습니다 –

+0

문제가 없습니다! 내 대답을 다른 사람들이 볼 수 있도록 허용 된 대답으로 표시하십시오. –