当窗口大小改变时,如何让textInput重新调整以适应静态窗口小部件

2024-03-28 17:09:15 发布

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

我正在尝试在两个大小不变的小部件之间锚定一个小部件

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()