Kivy:在 BoxLayout 中需要增加 space?
Kivy: Increasing space needed in BoxLayout?
我在当前 GUI 的左上角塞了很多东西,我试图基本上展开并让我的图像成为正常大小(类似于下面显示的模型)。我想我需要向下扩展 Y 方向以适应它(使顶部区域更大以适合所有区域)?但是,当我将 size_hint_y
更改为 > 1 时,它会将文本向上隔开,并在 GUI 之外切断。有任何想法吗?非常感谢!
当前布局:
我的目标:
我的 kv 文件:
#:kivy 1.10.0
<WeatherWidget>:
cols: 1
BoxLayout:
size_hint_y: None
BoxLayout:
size_hint_x: 1
size_hint_y: 1
orientation: "vertical"
Image:
source: 'Code32.png'
keep_ratio: False
halign: 'center'
Label:
text: root.current_temperature()[:3]
bold: True
font_size: 40
Label:
text: root.high_low_temp(0)
font_size: 15
color: [1,255,1,1]
Label:
text: root.get_location()
font_size: 15
color: [1,1,1,1]
bold: True
Label:
text: root.sunrise()
font_size: 10
color: [1,1,1,1]
Label:
text: root.sunset()
font_size: 10
color: [1,1,1,1]
BoxLayout:
orientation: 'vertical'
Image:
source: 'Code32.png'
Label:
text: root.forecast_day(1)
Label:
text: root.high_low_temp(1)
font_size: 12
color: [1,255,1,1]
Label:
text: root.forecast_day(2)
Label:
text: root.forecast_day(3)
Label:
text: root.forecast_day(4)
Label:
text: root.forecast_day(5)
BoxLayout:
size_hint_y: None
BoxLayout:
orientation: 'vertical'
Button:
text: root.TimeHours + ':' + root.TimeMinutes
size_hint_x: 1
font_size: 40
size: self.size
bold: True
halign: 'center'
Label:
text: root.current_date()
size_hint_x: 1
font_size: 15
bold: True
halign: 'center'
解决方法如下:
1。将 Window 分成 2 个部分
使用 size_hint_y = 0.3 将顶部部分设置为父级高度的 30% (0.3)。使用 size_hint_y = 0.7
将底部部分设为父项高度的 70% (0.7)
2。避免左上角堵塞
要展开左上角的小部件,请使用 size_hint_y = 1
片段
BoxLayout:
orientation: "vertical"
size_hint_y: 0.3
BoxLayout:
size_hint_y: 1
BoxLayout:
orientation: "vertical"
Image:
dailyview.kv
#:kivy 1.10.0
<WeatherWidget>:
cols: 1
BoxLayout:
orientation: "vertical"
size_hint_y: 0.3
BoxLayout:
size_hint_y: 1
orientation: "horizontal"
BoxLayout:
orientation: "vertical"
Image:
source: 'Weather/partly_cloudy_night@2x.png'
keep_ratio: False
halign: 'center'
Label:
text: root.current_temperature()[:3]
bold: True
font_size: 40
Label:
text: root.low_high_temp(0)
font_size: 15
color: [1,255,1,1]
Label:
text: root.get_location()
font_size: 15
color: [1,1,1,1]
bold: True
Label:
text: root.sunrise()
font_size: 10
color: [1,1,1,1]
Label:
text: root.sunset()
font_size: 10
color: [1,1,1,1]
BoxLayout:
orientation: 'vertical'
Image:
source: 'Weather/partly_cloudy_day@2x.png'
Label:
text: root.forecast_day(1)
Label:
text: root.low_high_temp(1)
font_size: 12
color: [1,255,1,1]
Label:
text: root.forecast_day(2)
Label:
text: root.forecast_day(3)
Label:
text: root.forecast_day(4)
Label:
text: root.forecast_day(5)
BoxLayout:
size_hint_y: None
BoxLayout:
orientation: 'vertical'
Button:
text: root.TimeHours + ':' + root.TimeMinutes
size_hint_x: 1
font_size: 40
size: self.size
bold: True
halign: 'center'
Label:
text: root.current_date()
size_hint_x: 1
font_size: 15
bold: True
halign: 'center'
BoxLayout:
size_hint_y: 0.8
BoxLayout:
size_hint_y: 0.7
BoxLayout:
Button:
size_hint_y: 1
text: "News Sections"
BoxLayout:
orientation: "vertical"
Button:
size_hint_y: 0.5
text: "Stock Quotes"
Button:
size_hint_y: 0.5
text: "Live Sports Scores"
输出
我在当前 GUI 的左上角塞了很多东西,我试图基本上展开并让我的图像成为正常大小(类似于下面显示的模型)。我想我需要向下扩展 Y 方向以适应它(使顶部区域更大以适合所有区域)?但是,当我将 size_hint_y
更改为 > 1 时,它会将文本向上隔开,并在 GUI 之外切断。有任何想法吗?非常感谢!
当前布局:
我的目标:
我的 kv 文件:
#:kivy 1.10.0
<WeatherWidget>:
cols: 1
BoxLayout:
size_hint_y: None
BoxLayout:
size_hint_x: 1
size_hint_y: 1
orientation: "vertical"
Image:
source: 'Code32.png'
keep_ratio: False
halign: 'center'
Label:
text: root.current_temperature()[:3]
bold: True
font_size: 40
Label:
text: root.high_low_temp(0)
font_size: 15
color: [1,255,1,1]
Label:
text: root.get_location()
font_size: 15
color: [1,1,1,1]
bold: True
Label:
text: root.sunrise()
font_size: 10
color: [1,1,1,1]
Label:
text: root.sunset()
font_size: 10
color: [1,1,1,1]
BoxLayout:
orientation: 'vertical'
Image:
source: 'Code32.png'
Label:
text: root.forecast_day(1)
Label:
text: root.high_low_temp(1)
font_size: 12
color: [1,255,1,1]
Label:
text: root.forecast_day(2)
Label:
text: root.forecast_day(3)
Label:
text: root.forecast_day(4)
Label:
text: root.forecast_day(5)
BoxLayout:
size_hint_y: None
BoxLayout:
orientation: 'vertical'
Button:
text: root.TimeHours + ':' + root.TimeMinutes
size_hint_x: 1
font_size: 40
size: self.size
bold: True
halign: 'center'
Label:
text: root.current_date()
size_hint_x: 1
font_size: 15
bold: True
halign: 'center'
解决方法如下:
1。将 Window 分成 2 个部分
使用 size_hint_y = 0.3 将顶部部分设置为父级高度的 30% (0.3)。使用 size_hint_y = 0.7
将底部部分设为父项高度的 70% (0.7)2。避免左上角堵塞
要展开左上角的小部件,请使用 size_hint_y = 1
片段
BoxLayout:
orientation: "vertical"
size_hint_y: 0.3
BoxLayout:
size_hint_y: 1
BoxLayout:
orientation: "vertical"
Image:
dailyview.kv
#:kivy 1.10.0
<WeatherWidget>:
cols: 1
BoxLayout:
orientation: "vertical"
size_hint_y: 0.3
BoxLayout:
size_hint_y: 1
orientation: "horizontal"
BoxLayout:
orientation: "vertical"
Image:
source: 'Weather/partly_cloudy_night@2x.png'
keep_ratio: False
halign: 'center'
Label:
text: root.current_temperature()[:3]
bold: True
font_size: 40
Label:
text: root.low_high_temp(0)
font_size: 15
color: [1,255,1,1]
Label:
text: root.get_location()
font_size: 15
color: [1,1,1,1]
bold: True
Label:
text: root.sunrise()
font_size: 10
color: [1,1,1,1]
Label:
text: root.sunset()
font_size: 10
color: [1,1,1,1]
BoxLayout:
orientation: 'vertical'
Image:
source: 'Weather/partly_cloudy_day@2x.png'
Label:
text: root.forecast_day(1)
Label:
text: root.low_high_temp(1)
font_size: 12
color: [1,255,1,1]
Label:
text: root.forecast_day(2)
Label:
text: root.forecast_day(3)
Label:
text: root.forecast_day(4)
Label:
text: root.forecast_day(5)
BoxLayout:
size_hint_y: None
BoxLayout:
orientation: 'vertical'
Button:
text: root.TimeHours + ':' + root.TimeMinutes
size_hint_x: 1
font_size: 40
size: self.size
bold: True
halign: 'center'
Label:
text: root.current_date()
size_hint_x: 1
font_size: 15
bold: True
halign: 'center'
BoxLayout:
size_hint_y: 0.8
BoxLayout:
size_hint_y: 0.7
BoxLayout:
Button:
size_hint_y: 1
text: "News Sections"
BoxLayout:
orientation: "vertical"
Button:
size_hint_y: 0.5
text: "Stock Quotes"
Button:
size_hint_y: 0.5
text: "Live Sports Scores"