【问题标题】:Kivy trouble with nested screenmanager嵌套屏幕管理器的 Kivy 问题
【发布时间】:2016-09-24 17:35:36
【问题描述】:

我正在尝试使用一些菜单切换按钮创建屏幕,然后创建一个嵌套的屏幕管理器,我只能在容器内切换屏幕管理器,并将菜单留在容器外。当我使用 Boxlayouts 和 Gridlayouts 的组合时,一切都在彼此之上。

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.graphics.context_instructions import Color
from kivy.uix.screenmanager import Screen, ScreenManager

class ScreenManagement(FloatLayout):
    pass

class IomApp(App):
    def build(self):
        return ScreenManagement()

if __name__ == '__main__':
    IomApp().run()

基维文件:

<LabelCases@Label>:
    height: '40dp'
    font_size: 18

<TextInputCases@TextInput>:
    height: '40dp'
    size_hint_y: None
    font_size: 18
    write_tab: False
    multiline: False
    on_text_validate: root.foo()

<ScreenManagement>:
    BoxLayout:
        orientation: "vertical"

        BoxLayout:
            height: "80dp"
            size_hint_y: None
            Label:
                text: 'Patient info Label'

        BoxLayout:
            orientation: 'horizontal'

            BoxLayout:
                orientation: 'vertical'
                size_hint_x: 20

                ToggleButton:
                    text: 'Case Info'
                    group: 'g1'
                    on_screen:

                ToggleButton:
                    text: 'Modalities'
                    group: 'g1'

                ToggleButton:
                    text: 'Report Editing'
                    group: 'g1'

                ToggleButton:
                    text: 'Printing/Exporting'
                    group: 'g1'

                ToggleButton:
                    text: 'Settings'
                    group: 'g1'

            BoxLayout:
                orientation: 'vertical'
                size_hint_x: 80

                ScreenManager:
                    id: "Screen1"

                    Screen:
                        name: "Case_info_screen"

                        BoxLayout:
                            orientation: 'vertical'
                            spacing: 20
                            orientation: 'vertical'
                            size_hint: (.5, .5)
                            pos_hint: {'center_x':.5, 'center_y':.5}

                            Label:
                                text: "Case Info"
                                size_hint_y: 25

                            GridLayout:
                                cols: 2
                                padding: 50
                                spacing: 15
                                size_hint_y: 50

                                LabelCases:
                                    text: 'First Name: '

                                TextInputCases:

                                LabelCases:
                                    text: 'Last Name: '
                                TextInputCases:

                                LabelCases:
                                    text: 'MRN: '
                                TextInputCases:

                                LabelCases:
                                    text: 'Date of Birth: '
                                TextInputCases:

                                LabelCases:
                                    text: 'Hospital: '
                                TextInputCases:

                                LabelCases:
                                    text: 'Diagnosis: '
                                TextInputCases:

                            Label:
                                text: "Surgical and Techical Staff"
                                size_hint_y: 25

                BoxLayout:

                    Button:
                        height: "40dp"
                        size_hint_y: None
                        text: "Back"
                    Button:
                        height: "40dp"
                        size_hint_y: None
                        text: "Next"

【问题讨论】:

    标签: python-3.x kivy


    【解决方案1】:

    您已经使用了布局,但即使您使布局的大小相对于其子级的大小是固定/静态 (height: '40dp')。如果你从TextInputCases 中删除size_hint_y: None,你会看到发生了什么。

    你的kv码

    <LabelCases@Label>:
        font_size: 18
    
    <TextInputCases@TextInput>:
        font_size: 18
        write_tab: False
        multiline: False
        on_text_validate: root.foo()
    
    <ScreenManagement>:
        BoxLayout:
            orientation: "vertical"
    
            BoxLayout:
                height: "80dp"
                size_hint_y: None
                Label:
                    text: 'Patient info Label'
    
            BoxLayout:
                orientation: 'horizontal'
    
                BoxLayout:
                    orientation: 'vertical'
                    size_hint_x: .20
    
                    ToggleButton:
                        text: 'Case Info'
                        group: 'g1'
                        on_screen:
    
                    ToggleButton:
                        text: 'Modalities'
                        group: 'g1'
    
                    ToggleButton:
                        text: 'Report Editing'
                        group: 'g1'
    
                    ToggleButton:
                        text: 'Printing/Exporting'
                        group: 'g1'
    
                    ToggleButton:
                        text: 'Settings'
                        group: 'g1'
    
                BoxLayout:
                    orientation: 'vertical'
                    size_hint_x: .80
    
                    ScreenManager:
                        id: "Screen1"
    
                        Screen:
                            name: "Case_info_screen"
    
                            BoxLayout:
                                orientation: 'vertical'
                                spacing: 20
                                orientation: 'vertical'
                                size_hint: (.5, .8)
                                pos_hint: {'center_x':.5, 'center_y':.5}
    
                                Label:
                                    text: "Case Info"
                                    size_hint_y: .25
    
                                GridLayout:
                                    cols: 2
                                    padding: 50
                                    spacing: 15
                                    size_hint_y: .70
    
                                    LabelCases:
                                        text: 'First Name: '
    
                                    TextInputCases:
    
                                    LabelCases:
                                        text: 'Last Name: '
                                    TextInputCases:
    
                                    LabelCases:
                                        text: 'MRN: '
                                    TextInputCases:
    
                                    LabelCases:
                                        text: 'Date of Birth: '
                                    TextInputCases:
    
                                    LabelCases:
                                        text: 'Hospital: '
                                    TextInputCases:
    
                                    LabelCases:
                                        text: 'Diagnosis: '
                                    TextInputCases:
    
                                Label:
                                    text: "Surgical and Techical Staff"
    
                    BoxLayout:
                        height: "40dp"
                        size_hint_y: None
                        Button:
                            text: "Back"
                        Button:
                            text: "Next"
    

    但我宁愿建议制作类似 ScrollView -> GridLayout -> all children 之类的东西,这样您就可以拥有固定大小的内容(具有滚动能力)并保留类似“iframe”的布局。 ^^

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多