2017-03-13 8 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) 

Ex。

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

あなたLabelが画面と同じサイズであるため、起こって:txtファイルからのデータ。それはあなたのコードを作るのに役立ちますので、これを防ぐためにあなたが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

関連する問題