Snow bunting
Snow bunting

Reputation: 1221

Kivy: property to fixed value

How do I get the fixed window size at one point in time? (s.t. this value will not change later)

I would like to add an image:

Image:
    width: self.parent.width
    height: self.parent.height
    size_hint: None, None

which should keep its initial size when rescaling the window. I can do this like

Image:
    width: 800
    height: 800
    size_hint: None, None

But I can't get the windows current dimensions in a way that they stay constant when rescaling the window later.

Thanks for your help.

Upvotes: 1

Views: 41

Answers (1)

Kacperito
Kacperito

Reputation: 1347

The only way I can think of is to do it outside of your .kv file. Precisely, you can set the values on any event triggered, such as on button press or when starting your app, just like that:

from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window


class Main(App):

    def build(self):
        base = Builder.load_file("main.kv")

        base.ids.img.width = Window.width
        base.ids.img.height = Window.height

        return base

In the example provided the width and height are set only once, when building the app. Alternatively you could achieve the same behaviour by moving the code to the __init__ of your class and access the image whenever you'd like to by calling self.base.ids.img (under the assumption you provide self.base).

Upvotes: 1

Related Questions