Tilt card#
#
Added in version 2.0.1.
The TiltCard widget is a ready-to-use 3D interactive card
that combines background image loading, custom 3D projection, and floating
text layers into a single component powered by
TiltBehavior.
Features#
Asynchronous Image Loading with Aspect Ratio Support: Uses
FitImageto fetch, scale, and cover card background spaces seamlessly.Floating Parallax Text Container: Supports a specialized
TiltTextContainerthat automatically positions and floats text content above the card using 3D translation matrices.Responsive Text Wrapping: Automatically calculates available dimensions and wraps inner
MDLabelinstances to prevent text overflowing the card boundaries.
Base example#
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
KV = '''
<MyScreen>:
md_bg_color: self.theme_cls.backgroundColor
TiltCard:
source: "bg.png"
card_size: dp(200), dp(340)
container_pos: dp(15), dp(15)
corner_radius: 24
pos_hint: {"center_x": .5, "center_y": .5}
TiltTextContainer:
spacing: dp(4)
MDLabel:
text: "Grey-winged\nBlackbird"
font_style: "Title"
role: "small"
bold: True
adaptive_height: True
theme_text_color: "Custom"
text_color: "white"
MDLabel:
text: "Turdus boulboul • Himalayas"
font_style: "Body"
role: "small"
adaptive_height: True
theme_text_color: "Custom"
text_color: "white"
'''
class MyScreen(MDScreen):
pass
class TiltTest(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
Builder.load_string(KV)
return MyScreen()
TiltTest().run()
from kivy.metrics import dp
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import MDScreen
from kivymd.uix.tilt import TiltCard, TiltTextContainer
class MyScreen(MDScreen):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.md_bg_color = self.theme_cls.backgroundColor
self.widgets = [
TiltCard(
TiltTextContainer(
MDLabel(
text="Grey-winged\nBlackbird",
font_style="Title",
role="small",
bold=True,
adaptive_height=True,
theme_text_color="Custom",
text_color="white",
),
MDLabel(
text="Turdus boulboul • Himalayas",
font_style="Body",
role="small",
adaptive_height=True,
theme_text_color="Custom",
text_color="white",
),
spacing=dp(4)
),
source='bg.png',
card_size=(dp(200), dp(340)),
container_pos=(dp(15), dp(15)),
corner_radius=24,
pos_hint={"center_x": .5, "center_y": .5}
)
]
class TiltTest(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
return MyScreen()
TiltTest().run()
API - kivymd.uix.tilt.tiltcard#
- class kivymd.uix.tilt.tiltcard.TiltTextContainer(*args, **kwargs)#
A vertical layout container specifically designed to hold text elements inside a
TiltCard. It automatically adapts its height to its children.For more information, see in the
MDBoxLayoutclass documentation.
- class kivymd.uix.tilt.tiltcard.TiltCard(container=None, **kwargs)#
A 3D interactive card widget.
Inherits from
TiltBehavior(providing the 3D projection, glare, and parallax shaders) and the standard KivyWidget. UsesFitImageto render aspect-ratio corrected background images.For more information, see in the
DeclarativeBehaviorandTiltBehaviorandWidgetclasses documentation.- source#
URL or path to the background image.
sourceis anStringPropertyand defaults to “”.
- container#
Reference to the child text container.
containeris anObjectPropertyand defaults to None.
- container_pos#
X and Y padding/offset for the text container from the bottom-left corner.
container_posis anListPropertyand defaults to [dp(15), dp(15)].
- add_widget(widget, *args, **kwargs)#
Add a new widget as a child of this widget.
- Parameters:
- widget:
Widget Widget to add to our list of children.
- index: int, defaults to 0
Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.
Added in version 1.0.5.
- canvas: str, defaults to None
Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.
Added in version 1.9.0.
- widget:
>>> from kivy.uix.button import Button >>> from kivy.uix.slider import Slider >>> root = Widget() >>> root.add_widget(Button()) >>> slider = Slider() >>> root.add_widget(slider)