Skip to content

Kivy Gotchas

Richard Arthurs edited this page Apr 8, 2018 · 1 revision

There are several quirks that you need to know about when using Kivy.

1. Classes must be capitalized

Let's say you want to override Kivy's /TabbedPanelItem/ class to create a tab with our own functionality. In order for this to work, your new class name must start with a capital letter.

OK: class UARTTab(TabbedPanelItem):

No good: class properClassConvention(TabbedPanelItem):

In the .kv file, your class must have the same name as the python class: <UARTTab>:

2. .kv files use python

Under an object in a .kv file, the code to the right of any : after an attribute can be any python code.

<UARTTab>: # the main UART tab text: 'UART' #python comment is ok BoxLayout: id: bl1 width: 23 * 2

3. size_hint

A size_hint attribute will tell Kivy what size to make an element - ish. Similar to the "box model" used in CSS, the width values in a size_hint are percentages of the parent's value, represented as a value between 0 and 1 for 0-100%.

You can do size_hint_x: 0, size_hint_y: 0, or size_hint: 0, 0 where 0 is the value you want.

You must set size_hint: (either x, y, or both) to None before you set the width attribute

Clone this wiki locally