Search code examples
pythonkivykivy-language

Can you wrap lines in a kivy file?


I have a couple of lines in my kv. file that are really long (80+ chars), and I was wondering if there was a way to wrap/continue them on the next line.

For example, how do I go from this

Line:
    points: self.pos[0] + 5, self.pos[1] + 2, self.pos[0] + self.width - 5, self.pos[1] + 2

to

Line:
    points: self.pos[0] + 5, self.pos[1] + 2, 
            self.pos[0] + self.width - 5, self.pos[1] + 2

or something similar.


Solution

  • Acording to https://kivy.org/docs/api-kivy.lang.html#valid-expressons, you can use line continuation character (\):

    Line:
        points:
            self.pos[0] + 5, self.pos[1] + 2,\ 
            self.pos[0] + self.width - 5, self.pos[1] + 2
    

    New line shouldn’t add an indentation level. Note that the following syntax is invalid:

    Line:
        points: self.pos[0] + 5, self.pos[1] + 2,\ 
                self.pos[0] + self.width - 5, self.pos[1] + 2
    

    Another valid example:

    canvas:
        Rectangle:
            pos:
                self.center_x-5,\
                0
            size:
                10,\
                self.height