Kivy: Add a raw widget to the GridLayout (unlike Image, Button, etc.).

Still exploring all the features of Qiwi, but I have an interesting problem. Let's say I have GridLayout, for example:

class MainApp(App):

    def build(self):
        self.root = GridLayout(cols=2)

        for i in range(4):
            self.root.add_widget(Button(text='Button {}'.format(i)))

        return self.root

I get this (as expected):

However, when I try to make each of these quadrants dynamic containers instead of plain old Button, Label, Imageetc., widgets (for example):

class Container(Widget):

    def __init__(self, *args, **kwargs):
        _id = kwargs.pop('button_id')
        super(Container, self).__init__(*args, **kwargs)

        self.add_widget(Button(text="Button {}".format(_id)))


class MainApp(App):

    def build(self):
        self.root = GridLayout(cols=2)

        for i in range(4):
            self.root.add_widget(Container(button_id=i))

        return self.root

I get this:

Please note that regardless of the size of the window, each widget is located in the lower left corner and supports a small size.

What happens with the addition of Kivy widget types that do this job, but using objects Widgetas buckets of other objects Widgetdoes not work?

0
1

Container kivy.uix.layout.Layout (, kivy.uix.layout.BoxLayout).

:

- (100, 100). , http://kivy.org/docs/api-kivy.uix.layout.html#kivy.uix.layout.Layout. , , , : .

+2

Source: https://habr.com/ru/post/1651238/


All Articles