A
A
Andrei1penguin12021-05-06 19:28:08
Python
Andrei1penguin1, 2021-05-06 19:28:08

How to set widget size in percentage?

Good day, let's have a widget:
Python code:

class MyWidget(Widget):
    pass
 
class MainWidget(App):
 
    def build(self):
        main_widget = BoxLayout(orientation="horizontal")
        main_widget.add_widget(MyWidget())
        return main_widget

KV code:
<MyWidget>:
    canvas:
        Color:
            rgba: (0.3, 0.3, 0.3, 1)
        Rectangle:
            pos: self.pos
            size: self.size

And you need to make it so that it is not the full width of the window, but only half.
That is, something like self.size = 50%, 100%
I did not find anything about this in the documentation. Can
you please tell me how this can be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yupiter7575, 2021-05-06
@Andrei1penguin1

size_hint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question