Version

Quick search

Table Of Contents

Cover Behavior

The CoverBehavior mixin is intended for rendering textures to full widget size keeping the aspect ratio of the original texture.

Use cases are i.e. rendering full size background images or video content in a dynamic layout.

For an overview of behaviors, please refer to the behaviors documentation.

Example

The following examples add cover behavior to an image:

In python:

from kivy.app import App
from kivy.uix.behaviors import CoverBehavior
from kivy.uix.image import Image


class CoverImage(CoverBehavior, Image):

    def __init__(self, **kwargs):
        super(CoverImage, self).__init__(**kwargs)
        texture = self._coreimage.texture
        self.reference_size = texture.size
        self.texture = texture


class MainApp(App):

    def build(self):
        return CoverImage(source='image.jpg')

MainApp().run()

In Kivy Language:

CoverImage:
    source: 'image.png'

<CoverImage@CoverBehavior+Image>:
    reference_size: self.texture_size

See CoverBehavior for details.

class kivy.uix.behaviors.cover.CoverBehavior(**kwargs)[source]

Bases: builtins.object

The CoverBehavior mixin provides rendering a texture covering full widget size keeping aspect ratio of the original texture.

New in version 1.10.0.

cover_pos

Position of the aspect ratio aware texture. Gets calculated in CoverBehavior.calculate_cover.

cover_pos is a ListProperty and defaults to [0, 0].

cover_size

Size of the aspect ratio aware texture. Gets calculated in CoverBehavior.calculate_cover.

cover_size is a ListProperty and defaults to [0, 0].

reference_size

Reference size used for aspect ratio approximation calculation.

reference_size is a ListProperty and defaults to [].