Kirat Kirat - 2 months ago 18
Python Question

Button position in kivy gridlayout

I'm trying to move this button to top-right but no matters what I do I just can't move it. It is always in the bottom-left and never leaves this position.

This is my .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()


And this is my .kv

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

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

Answer

I suggest using relative layout. for example

RelativeLayout:

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

change center_x and center_y till they meet your needs.

Comments