Kirat Kirat - 10 months ago 71
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:

# coding=UTF-8

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


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)
#return layout
CF = TestS()
return CF


And this is my .kv

rows: 1
cols: 1
padding: 3
spacing: 3

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

Answer Source

I suggest using relative layout. for example


        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.