2016-09-23 74 views
0

我試圖將此按鈕移到右上方,但不管我做什麼我只是無法移動它。這是總是在左下角,從來沒有離開這個位置。kivy gridlayout中的按鈕位置

這是我的.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} 
+0

你想把按鈕放在哪裏? – Juggernaut

+0

它將成爲screem的頂部 – Kirat

回答

2

我建議使用相對佈局。例如

RelativeLayout: 

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

變化center_xcenter_y,直到他們滿足您的需求。

+0

它不工作,這個按鈕覆蓋所有的screem,我想添加更多的3個按鈕... 2頂部和2機器人 – Kirat

+0

使用'size_hint:無,None「,然後使用'size:400,400'或任意大小來定義尺寸 – Juggernaut

+0

This works,Thank you very much,finally worked well = D – Kirat