A
A
Andrei1penguin12021-05-24 13:23:29
Python
Andrei1penguin1, 2021-05-24 13:23:29

How to get the actual dimensions of a kivy widget?

Good day, I ran into such a problem that when calling self.size on a widget, the result 100,100 is returned.
Googled that this is due to the fact that the default sizes do not change, and in order to change them, you can write something like:

def __init__(self):
    super().__init__()
    self.bind(size=self.update)

But the trouble is that the widget does not have such a function (update), only LAYOUTs have it. Can
you please tell me how to get the actual sizes of the widgets, and not the sizes set by default?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-05-24
@alexbprofit

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.layout import Layout

kv = '''
<Foo>:
    on_touch_down: print(self.size)
'''
Builder.load_string(kv)

class Foo(Layout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        print (self.size)

class MyApp(App):
    def build(self):
        return Foo()

MyApp().run()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question