Kivy:增加BoxLayout所需的空间?

2024-06-26 17:01:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在当前GUI的左上角有很多卡住的地方,我试图基本上分散开来,让我的图像保持正常大小(类似于下面显示的模型)。我想我需要向下扩展Y方向来适应它(使顶部区域更大以适应所有的情况)?但是,当我将size_hint_y改为>;1时,它会使文本向上间隔,并在GUI外部被切断。有什么想法吗?非常感谢!在

当前布局: enter image description here

我的目标: enter image description here

我的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'

Tags: texttruesizerootlabelcolorfontbold
1条回答
网友
1楼 · 发布于 2024-06-26 17:01:36

解决方法如下:

1。把窗户分成两部分

使用size_hint_y=0.3,将顶部部分设置为父级高度的30%(0.3)。使用size_hint_y=0.7将底部部分设置为父级高度的70%(0.7)

2。避免左上角卡住

要在左上角展开小部件,请使用size\u hint_y=1

代码段

BoxLayout:
    orientation: "vertical"
    size_hint_y: 0.3
    BoxLayout:
        size_hint_y: 1
        BoxLayout:
            orientation: "vertical"
            Image:

在每日视图.kv在

^{pr2}$

输出

Figure 1 - Buttons for News, Stock Quotes, and Live Sports ScoresFigure 2 - Using RecycleView

相关问题 更多 >