【问题标题】:How to push kivy widget to the top of the screen如何将kivy小部件推到屏幕顶部
【发布时间】:2020-10-03 10:17:04
【问题描述】:

我很难将我的小部件与 kivy 中的窗口顶部对齐,这是图示。我的期望是在底部添加一个空小部件会将小部件推到屏幕顶部,但它只会到达屏幕中间。任何指导都会有所帮助。

布局

.kv 文件

#:import utils kivy.utils
#: import Window kivy.core.window.Window

<FlatButton@ButtonBehavior+Label>:
    font_size: 14

<PosWindow>:
    id: main_win
    orientation: 'vertical'
    canvas.before:
        Color:
            rgb: utils.get_color_from_hex('#ffffff')
        Rectangle:
            size: self.size
            pos: self.pos

    BoxLayout:
        spacing: 0
        orientation: 'vertical'

    #THE BEGINNNING OF THE TOP BAR
    BoxLayout:
        size_hint_y: None
        height: 30

        Label:
            text: 'HEADER POSITION'
            size_hint_x: .6
            bold: True
            color: (1,1,1,1)
            canvas.before:
                Color:
                    rgb: utils.get_color_from_hex('#5B2437')
                Rectangle:
                    size: self.size
                    pos: self.pos


        Label:
            text: 'The Name'
            size_hint_x: .4
            height: 30
            bold: True
            color: (1,1,1,1)
            canvas.before:
                Color:
                    rgb: utils.get_color_from_hex('#5B2437')
                Rectangle:
                    size: self.size
                    pos: self.pos
    # THE END OF THE TOP BAR




    #THE BEGINNING OF THE SECOND WAVE FULL
    BoxLayout:
        id: current
        size_hint_y: None
        height: 50
        canvas.before:
            Color:
                rgba: (1,1,1, 1)
            Rectangle:
                size: self.size
                pos: self.pos
        Button:
            text: 'Current Item:'
            background_normal: ''
            background_color: (.06, .32, .32, 1)
            size_hint_x: .4
        Button:
            id: cur_product
            text: 'Default Product'
            background_normal: ''
            background_color: (.06, .4, .4, 1)
        Button:
            id: cur_price
            text: '0.00'
            background_normal: ''
            background_color: (.06, .65, .65, 1)
            size_hint_x: .2

    Widget: #To place everything at the top of the screen
    #THE END OF THE SECOND WAVE FULL



    #SEARCH FOR A PRODUCT
    BoxLayout:
        id: current
        orientation: 'horizontal'
        size_hint_y: None
        height: 50
        canvas.before:
            Color:
                rgba: (1,1,1, 1)
            Rectangle:
                size: self.size
                pos: self.pos

        BoxLayout:
            size_hint_x: .4
            id: searchBox
            canvas.before:
                Color:
                    rgba: (.06, .75, .35, 1)
                Rectangle:
                    size: self.size
                    pos: self.pos


        BoxLayout:
            size_hint_x: .6
            id: previewBox
            canvas.before:
                Color:
                    rgba: (.06, .35, .85, 1)
                Rectangle:
                    size: self.size
                    pos: self.pos

    Widget:

【问题讨论】:

    标签: python kivy desktop-application kivy-language


    【解决方案1】:

    我发现,我必须先删除第一个 BoxLayout,然后再删除除最后一个 boxlayout 之外的空小部件。

    #:import utils kivy.utils
    #: import Window kivy.core.window.Window
    
    <FlatButton@ButtonBehavior+Label>:
        font_size: 14
    

    : 编号:main_win 方向:“垂直” 画布之前: 颜色: rgb: utils.get_color_from_hex('#ffffff') 长方形: 尺寸:self.size pos: self.pos

    #THE BEGINNNING OF THE TOP BAR
    BoxLayout:
        size_hint_y: None
        height: 30
    
        Label:
            text: 'HEADER POSITION'
            size_hint_x: .6
            bold: True
            color: (1,1,1,1)
            canvas.before:
                Color:
                    rgb: utils.get_color_from_hex('#5B2437')
                Rectangle:
                    size: self.size
                    pos: self.pos
    
    
        Label:
            text: 'The Name'
            size_hint_x: .4
            height: 30
            bold: True
            color: (1,1,1,1)
            canvas.before:
                Color:
                    rgb: utils.get_color_from_hex('#5B2437')
                Rectangle:
                    size: self.size
                    pos: self.pos
    
    
    #THE BEGINNING OF THE SECOND WAVE FULL
    BoxLayout:
        id: current
        size_hint_y: None
        height: 50
        canvas.before:
            Color:
                rgba: (1,1,1, 1)
            Rectangle:
                size: self.size
                pos: self.pos
        Button:
            text: 'Current Item:'
            background_normal: ''
            background_color: (.06, .32, .32, 1)
            size_hint_x: .4
        Button:
            id: cur_product
            text: 'Default Product'
            background_normal: ''
            background_color: (.06, .4, .4, 1)
        Button:
            id: cur_price
            text: '0.00'
            background_normal: ''
            background_color: (.06, .65, .65, 1)
            size_hint_x: .2
    #THE END OF THE SECOND WAVE FULL
    
    
    
     #SEARCH FOR A PRODUCT
    BoxLayout:
        id: current
        orientation: 'horizontal'
        size_hint_y: None
        height: 50
        canvas.before:
            Color:
                rgba: (1,1,1, 1)
            Rectangle:
                size: self.size
                pos: self.pos
    
        BoxLayout:
            size_hint_x: .4
            id: searchBox
            canvas.before:
                Color:
                    rgba: (.06, .75, .35, 1)
                Rectangle:
                    size: self.size
                    pos: self.pos
    
    
        BoxLayout:
            size_hint_x: .6
            id: previewBox
            canvas.before:
                Color:
                    rgba: (.06, .35, .85, 1)
                Rectangle:
                    size: self.size
                    pos: self.pos
    
    Widget:
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2022-11-13
      相关资源
      最近更新 更多