lundi 11 juillet 2016

Aligning Kivy objects using pure Python


I can't seem to figure out alignment using pure Python code. My understanding is that we reference root to get relational alignment. However, I haven't been able to get it to work. This code compiles, runs, and then places the button in the bottom left corner. At the 0,0 coords. What am I missing here?

class ContainerView(FloatLayout):
    def __init__(self, **kwargs):
        super(ContainerView, self).__init__(**kwargs)

    def build(self):
        new = Button()
        new.text = "username"
        new.size = (50,50)
        new.color = [3/255,50/255,155/255,1]
        new.size_hint = [0.5,0.5]
        new.center = self.center ###This line
        self.add_widget(new)


class ScoreboardApp(App):
    def build(self):
        cView = ContainerView()
        cView.build()
        return cView

Aucun commentaire:

Enregistrer un commentaire