Search code examples
pythonkivy

How to use Kivy allow_stretch?


Kivy allow_stretch function doesn't work. This is my code.

from kivy.app import App
from kivy.lang import Builder

kv = """
GridLayout:
    cols: 3
    Image:
        source: "images/cake.jpeg"
        allow_stretch: False
    Image:
        source: "images/cake.jpeg"
        allow_stretch: True
"""


class TestApp(App):
    def build(self):
        return Builder.load_string(kv)


TestApp().run()

I wish the pictures will be different, but they look same. It looks like: ](https://i.sstatic.net/3dHrs.jpg)


Solution

  • You can try to set your image size. They may be too big

    GridLayout:
        cols: 3
        Image:
            source: "images/cake.jpeg"
            size_hint: None, None
            size: 200, 200
            allow_stretch: False
        Image:
            source: "images/cake.jpeg"
            size_hint: None, None
            size: 200, 200
            allow_stretch: True