【问题标题】:Space in elements of GridLayout Python KivyGridLayout Python Kivy 元素中的空间
【发布时间】:2018-06-08 10:08:28
【问题描述】:

我正在编写一个简单的 python Kivy GUI 来读取用户选择的文件的内容。我遇到的问题是,在 Gui 的屏幕之后,内部 GridLayout 的元素中不需要空间。

代码输出

如您所见,有两个矩形空间我没有声明,.kv文件中写的相关代码是:

GridLayout:
        id: grid_1_level_one
        cols: 1
        rows: 3
        GridLayout:
            id: grid_1_level_two
            cols: 1
            rows: 1
            height: 100
            size_hint_y: None
            Label:
                id: title_parameters_view
                valign: 'middle'
                halign: 'center'
                text: "Parameters"
                size: self.texture_size
        GridLayout:
            id: grid_2_level_two
            cols: 2
            rows: 1
            #size_hint_y: None
            height: self.minimum_height
            FileChooserListView:
                id: visualize_file_chooser_variables
                canvas.before:
                    Color:
                        rgba: hex('#413FBF')
                    Rectangle:
                        pos: self.pos
                        size: self.size
                on_selection: root.selected_file(*args)
            RstDocument:
                id: document_parameter_viewer

        GridLayout:
            cols: 1
            rows: 1
            height: 30
            size_hint_y: None
            Button:
                id: button_home_visualize
                valign: 'middle'
                halign: 'center'
                text: "Turn to home"
                size: self.texture_size
                on_press: root.go_to_home()

你知道一些避免这种解决方案的技巧吗?

【问题讨论】:

    标签: python-2.7 kivy kivy-language


    【解决方案1】:

    解决方案是将 FileChooserListView 的高度 (self.y - 30) 减少按钮/最后一个 GridLayout (height: 30) 的高度。

    片段

            FileChooserListView:
                id: visualize_file_chooser_variables
                canvas.before:
                    Color:
                        rgba: hex('#413FBF')
                    Rectangle:
                        pos: self.x, self.y - 30
                        size: self.size
                on_selection: root.selected_file(*args)
    

    输出

    【讨论】: