Kivy layout file

Now that we have the logic for how the GUI is supposed to function, we can actually write the code to place the widgets where we want on the diagram. You could do this within the Python file that we just created, but best practice is to separate code logic from presentation. For example, the following code from the official Kivy tutorial shows how a Python file could both accept a touch from a finger and create a small dot on the screen of a tablet:

def on_touch_down(self, touch):    with self.canvas:        Color(1, 1, 0)        d = 30.        Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))

For our purposes, we will write a special .kv file to hold the layout-specific information and keep the Python logic in

# hmi.kv ...

Get Learn Programming in Python with Cody Jackson now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.