我试图建立我做的以下模拟:
我在很早的阶段,我试图找出如何细分左上角(显示图像,温度,高低,城市,日出,日落) )。在我到目前为止所做的工作中,我将其显示为一个按钮,以查看感兴趣的区域。我一直在尝试的一切都把它放到下面一个全新的区域(而不是细分第一个细胞)。谢谢!
这是我构建它的python文件:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.clock import Clock
from kivy.properties import StringProperty
from random import *
import time
from weather import Weather
# In the kv file, everything to the right of the colon is pure python
# for loading python module in kv file, use format of #: import keyword module_name
# Pull in the weather data
weather = Weather()
location = weather.lookup_by_location('New York, NY')
condition = location.condition()
forecasts = location.forecast()
astronomy = location.astronomy()
class WeatherWidget(GridLayout):
TimeSeconds = StringProperty('')
TimeMinutes = StringProperty('')
TimeHours = StringProperty('')
def current_location(self):
return location.title().replace('Yahoo! Weather - ','')
def current_temperature(self):
return condition['temp'] + '° ' +condition['text']
def update(self, dt):
current_time = time.localtime()
self.TimeHours = str(current_time.tm_hour).zfill(2)
self.TimeMinutes = str(current_time.tm_min).zfill(2)
self.TimeSeconds = str(current_time.tm_sec).zfill(2)
class DailyViewApp(App):
def build(self):
weather = WeatherWidget()
Clock.schedule_interval(weather.update, 1)
return weather
if __name__ == '__main__':
DailyViewApp().run()
这是Kivy代码:
#:kivy 1.10.0
<WeatherWidget>:
cols: 1
BoxLayout:
size_hint_y: None
Button:
text: root.current_temperature()
size_hint_x: 1
Label:
text: 'Tomorrow'
size_hint_x: 0.25
Label:
text: 'T+2'
size_hint_x: 0.25
Label:
text: 'T+3'
size_hint_x: 0.25
Label:
text: 'T+4'
size_hint_x: 0.25
Label:
text: 'T+5'
size_hint_x: 0.25
BoxLayout:
Label:
text: root.TimeHours + ':' + root.TimeMinutes
size_hint_x: 1
font_size: 30
bold: True
答案 0 :(得分:1)
是的,这是可能的。你只是嵌套另一个boxlayout 像这样:
<WeatherWidget>:
cols: 1
BoxLayout:
size_hint_y: None
BoxLayout:
size_hint_x: 1
orientation: "vertical"
Image:
src: "yourimage"
Button:
text: root.current_temperature()
Label:
text: 'Tomorrow'
size_hint_x: 0.25