afidegnum
afidegnum

Reputation: 171

TextInput and Button can't move to right

I m trying to adjust the pos_hint in order to shift the textINput to the right side with no success. what am i not doing right?

here is the current Kv. Language.

<MyScreenManager>:
    IntroScreen:

<IntroScreen>:
    name: 'introscreen'
    BoxLayout:
        orientation:'horizontal'
        BoxLayout:
            canvas:
                Color:
                    rgb: 0, 0.267, 0
                Rectangle:
                    size: self.size
            spacing: 10
            TextInput:
                id: login
                text: "Login"
                multiline: False
                size_hint: None, None
                height:60
                width: 140
                font_size: 30
                pos_hint:{'center_y': 0.5, 'center_x': 0.2, 'left': 0.8}

            Button:
                text: "Enter"
                size_hint: None, None
                size: 100, 63
                pos_hint:{'center_y': 0.5, 'center_x': 0.2, 'left': 0.8}
                on_release: root.current = 'mainpage'

here is the actual output i am getting.

TextInput and Button need to at the right side instead of left.

Upvotes: 0

Views: 98

Answers (1)

jligeza
jligeza

Reputation: 4693

You have created two widgets - text input and button - in a horizontal box layout, which covers the entire screen. You cannot shrink them and move to the right, because it creates a gap to the left, which is getting automatically filled.

You could set padding property in the inner box layout to create a gap to the left of text input. However, a better approach would be putting them together in a compact grid layout, and move freely:

<MyScreenManager>:
    IntroScreen:

<IntroScreen>:
    name: 'introscreen'

    canvas:
        Color:
            rgb: 0, 0.267, 0
        Rectangle:
            size: self.size

    GridLayout:
        rows: 1
        size_hint: None, None
        width: self.minimum_width  # combined width of child widgets
        height: self.minimum_height # combined height of child widgets
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
        spacing: 10

        TextInput:
            id: login
            text: "Login"
            multiline: False
            size_hint: None, None
            height:60
            width: 140
            font_size: 30

        Button:
            text: "Enter"
            size_hint: None, None
            size: 100, 63
            on_release: root.current = 'mainpage'

Upvotes: 1

Related Questions