Kivy:你能否在另一个BoxLayout中细分BoxLayout?(Kivy: Can you subdivide a BoxLayout within another BoxLayout?)

我正在尝试构建我制作的以下模型:

我处于早期阶段,我正试图弄清楚如何细分左上角(显示图像,温度,高低,城市,日出,日落)。 在迄今为止我所做的工作中,我将它显示为一个按钮来查看感兴趣的区域。 我一直试图把它放到一个全新的区域下面(而不是细分第一个单元格)。 谢谢!

这是我构建它的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 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

I'm trying to build the following mock up that I made:

I'm in the very early stages and I'm trying to figure out how I can sub-divide the top left corner (to display an image, the temperature, high low, city, sunrise, sunset). In what I've done so far, I displayed it as a button to see the region of interest. Everything I keep trying puts it into an entirely new region below (instead of subdividing the first cell). Thank you!

This is my python file to build it:

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

This is the Kivy code:

#: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

最满意答案

是的,这是可能的。 你只是嵌套另一个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

Yes that is possible. You just nest another boxlayout. Like this:

<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

更多推荐