首页 > 解决方案 > 每当窗口大小发生变化时,如何让 textInput 调整以适应静态小部件

问题描述

我正在尝试将一个小部件锚定在其他两个不改变大小的小部件之间。

https://gyazo.com/caf7044f97ef5cceed7aeb6328d6baab 我试图防止小部件重叠,但我不知道如何去做。我希望中间小部件调整大小以适应它两侧的小部件,也可能在它下方。

#:kivy 2.0.0 

<GeneratorScreen>:
    
    FloatLayout:
        pos:0,0
        size: root.width, root.height
        
        Label:
            id: text_editor_output
            background_color: (140, 146, 156, 1)
            text: "placeholder"
            size_hint:(.8, .8)
            pos_hint: {'x': .04, 'y': .04}
            pos_hint: {'bottom':1.0}

        TextInput:
            id: text_editor_input
            markup: True
            color: (255, 255, 255, 1)
            text: 'type here'
            size_hint:(.8, .8)
            pos_hint: {'x': .04, 'y': .04}
            pos_hint: {'bottom':1.0}
    

    AnchorLayout:
        anchor_x: "right"
        anchor_y: "top"
        size: root.width, root.height

        GridLayout:
            size_hint: None, None
            pos_hint: {'x': .9, 'y': 1}
            size:200, 200
            cols: 3
            pos_hint: {'right':1.0}

            Button:
                id: settlement_button
                text: 'Settlement'
                font_size: 10
                size_hint: None, None
                size: 67, 20
                on_press: root.settlement()

            Button:
                id: npc_button
                text: 'Npc'
                font_size: 10
                size_hint: None, None
                size: 67, 20 
                on_press: root.npc()

            Button:
                id: store_button
                text: 'Store'
                font_size: 10
                size_hint: None, None
                size: 67, 20 

            Button:
                id: other_button
                text: 'other'
                font_size: 10
                size_hint: None, None
                size: 67, 20 

    AnchorLayout:
        anchor_x: "right"
        anchor_y: "bottom"
        size: root.width, root.height

        TextInput:
            id: gen_output
            pos_hint: {'bottom': 1.0}
            pos_hint: {'right':1.0}
            size_hint: None, None
            size: 200, 200
            text: ''
            font_size: 15
            
                        
    AnchorLayout:
        anchor_x: "left"
        anchor_y: "top"
        size: root.width, root.height

        Button:
            size_hint: None, None
            size: 30,30
            text:"save"
            on_press: root.save()


标签: pythonuser-interfacekivykivy-language

解决方案


推荐阅读