Skip to content

Instantly share code, notes, and snippets.

@inclement
Created December 27, 2019 22:11
Show Gist options
  • Save inclement/a7a0064e5d1755b007ae03244db72711 to your computer and use it in GitHub Desktop.
Save inclement/a7a0064e5d1755b007ae03244db72711 to your computer and use it in GitHub Desktop.
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.clock import Clock
class SizeImage(Image):
pass
class ImagesGrid(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.bind(minimum_width=self.set_width,
width=self.set_width,
height=self.set_width,
children=self.set_width)
def set_width(self, instance, value):
self.width = len(self.children) * (680 / 1000) * self.height
root = Builder.load_string("""
<SizeImage>:
allow_stretch: True
keep_ratio: True
AnchorLayout:
ScrollView:
size_hint_x: None
width: min(root.width, image_grid.width)
ImagesGrid:
id: image_grid
rows: 1
size_hint_x: None
""")
for i in range(5):
root.ids.image_grid.add_widget(SizeImage(source="beauty.jpg"))
runTouchApp(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment