Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created April 28, 2020 18:25
Show Gist options
  • Save tshirtman/71f267f0b305f8613c06c019b1fe8320 to your computer and use it in GitHub Desktop.
Save tshirtman/71f267f0b305f8613c06c019b1fe8320 to your computer and use it in GitHub Desktop.
simple cover image / letterboxing implementation in kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
KV = '''
FloatLayout:
Image:
size_hint: None, None
source: 'landscape.png'
pos_hint: {'center': (.5, .5)}
taller: self.image_ratio > (root.width / root.height)
width: (root.height * self.image_ratio) if self.taller else root.width
height: (root.width / self.image_ratio) if not self.taller else root.height
allow_stretch:True
'''
class Application(App):
def build(self):
return Builder.load_string(KV)
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment