Python 基维:你能在另一个BoxLayout中细分一个BoxLayout吗?
我正在尝试构建我制作的以下模型: 我正处于非常早期的阶段,我正试图找出如何细分左上角(显示图像、温度、高低、城市、日出、日落)。在我到目前为止所做的工作中,我将其显示为一个按钮,以查看感兴趣的区域。我不断尝试的每件事都会将它放入下面一个全新的区域(而不是细分第一个单元格)。谢谢大家! 这是我构建它的python文件:Python 基维:你能在另一个BoxLayout中细分一个BoxLayout吗?,python,kivy,kivy-language,Python,Kivy,Kivy Language,我正在尝试构建我制作的以下模型: 我正处于非常早期的阶段,我正试图找出如何细分左上角(显示图像、温度、高低、城市、日出、日落)。在我到目前为止所做的工作中,我将其显示为一个按钮,以查看感兴趣的区域。我不断尝试的每件事都会将它放入下面一个全新的区域(而不是细分第一个单元格)。谢谢大家! 这是我构建它的python文件: from kivy.app import App from kivy.uix.gridlayout import GridLayout from kivy.clock impo
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
#:kivy 1.10.0
:
科尔斯:1
盒子布局:
尺寸提示:无
按钮:
文本:root.current_temperature()
大小提示:1
标签:
文字:“明天”
尺寸:0.25
标签:
文本:“T+2”
尺寸:0.25
标签:
文本:“T+3”
尺寸:0.25
标签:
文本:“T+4”
尺寸:0.25
标签:
文本:“T+5”
尺寸:0.25
盒子布局:
标签:
文本:root.TimeHours+':'+root.TimeMinutes
大小提示:1
字体大小:30
黑体字:对
是的,这是可能的。您只需嵌套另一个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
:
科尔斯:1
盒子布局:
尺寸提示:无
盒子布局:
大小提示:1
方向:“垂直”
图片:
src:“你的形象”
按钮:
文本:root.current_temperature()
标签:
文字:“明天”
尺寸:0.25
Awesome-确实如此-仍然通过Kivy工作,但他们确实比TKinter IMO更容易。谢谢!你会来的。我同意。