kivy gridlayout中的按钮位置

时间:2016-09-23 16:57:12

标签: python python-2.7 kivy kivy-language

我正在尝试将此按钮移至右上角,但无论我做什么我都无法移动它。 总是在左下角,永远不会离开这个位置。

这是我的.py:

    #!/usr/bin/python
    # coding=UTF-8

    import kivy
    from kivy.uix.gridlayout import GridLayout
    from kivy.app import App
    from kivy.uix.button import Button
    from kivy.lang import Builder

    Builder.load_file('listadex.kv')

    class TestS(GridLayout):
        def bt1(self):
            print 'Olar galera'        #layout.add_widget(bt1.Button(text='TestS'))

    class SegundaTela(App):
        def build(self):
    #layout = GridLayout(cols=2, row_force_default=False, row_default_height=10)
    #layout.add_widget(bt1.Button(text='TestS'))
    #layout.add_widget(bt2.Button(text='TestA'))
    #layout.add_widget(bt3.Button(text='TestD'))
    #layout.add_widget(bt4.Button(text='TestMC'))
    #return layout
    CF = TestS()
    return CF

    SegundaTela().run()

这是我的.kv

    <TestS>:
        GridLayout:
            rows: 1
            cols: 1
            padding: 3
            spacing: 3

            Button:
                text: 'botao1'
                on_press: root.bt1()
                pos_hint: {'center_x':.15}

1 个答案:

答案 0 :(得分:2)

我建议使用相对布局。例如

RelativeLayout:

    Button:
        text: 'botao1'
        on_press: root.bt1()
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}

更改center_xcenter_y,直到满足您的需求为止。