2017-03-13 2 views
0

앵커 레이블의 위치에 문제가있었습니다. Kivy는 중간/중앙에서이 코드를 실행합니다. 그것은 화면 디스플레이의 일부입니다.kivy에서 입력 텍스트가있는 레이블의 위치

with open('weatherdata.txt', encoding='utf-8') as weatherdata: 
     read_weatherdata = weatherdata.read() 

    label_position = AnchorLayout(anchor_x='right', 
            anchor_y='bottom') 
    label_settings = Label(text=read_weatherdata, 
          font_size='12sp', 
          size=(200, 200), 
          color=(0.4, 0.4, 0.4, 1)) 
    label_position.add_widget(label_settings) 
    self.add_widget(label_position) 

예. txt 파일에서 데이터 : 당신의 Label 화면과 같은 크기이기 때문에

Weather now in Warsaw, pl 

Clouds: 20 % 
Rain: 15 % 
Wind speed: 2.6 
Wind degree: 340 
Humidity: 75 % 
Temperature: 5.0 celsius 
Max temperature: 5.0 celsius 
Min temperature: 5.0 celsius 
Weather status: few clouds 

답변

0

일 이죠. 당신이해야이를 방지하기 위해 size_hint: None, None

이 코드가 여기에

이 개선 된 코드의 예입니다 많은 청소기 보이게하는 데 도움이 때문에이 kv lauguage 사용 방법을 추천 해드립니다 :

from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.anchorlayout import AnchorLayout 

Builder.load_string(''' 
<Root>: 
    anchor_x: 'right' 
    anchor_y: 'bottom' 

    Label: 
     id: weather_info 
     color: 0.4, 0.4, 0.4, 1 
     font_size: '12sp' 
     size_hint: None, None 
     size: self.texture_size # you can specify you own size here now 
''') 

class Root(AnchorLayout): 
    pass 

class TestApp(App): 
    def build(self): 
     weather_data=\ 
''' 
Weather now in Warsaw, pl 

Clouds: 20 % 
Rain: 15 % 
Wind speed: 2.6 
Wind degree: 340 
Humidity: 75 % 
Temperature: 5.0 celsius 
Max temperature: 5.0 celsius 
Min temperature: 5.0 celsius 
Weather status: few clouds 
''' 

     self.root = Root() 
     self.root.ids.weather_info.text = weather_data 
     return self.root 


TestApp().run() 

그리고 그 결과로 우리는이 :

(폰트가 너무 작고 어두운하지만 당신은 언제든지 쉽게 변경할 수 있습니다!) pic

,536,