Making tiles
This part of the chapter is devoted to building the Tile
widget. Tiles are more dynamic in nature than, for example, the Board
widget that we've seen earlier. To account for this, we are going to create a number of Kivy properties on the Tile
class so that any visible change to tile automatically leads to redrawing it.
Kivy properties differ from regular Python ones: a property in Python is basically just a variable bound to an instance of class, possibly coupled with getter and setter functions. In Kivy, properties have an additional feature: they emit events when changed and as such you can observe interesting properties and adjust other related variables accordingly, or perhaps repaint the screen.
Most of this work happens under the hood without your intervention: when you issue a change to, for example, the pos
or size
of a widget, an event (on_pos
or on_size
respectively) is fired.
Interestingly, all properties that are defined in a .kv
file are propagated automatically. For...