[Python] Python doesn't recognize element from .kv file

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    In the .py file I want to refer to an element from the .kv file, but I get a keyerror

    py:

    class graApp(App):
    def build(self):
    Window.clearcolor = (1, 1, 1, 1)
    layout = Builder.load_file('gra.kv')
    grid = layout.ids['board']
    #
    # for i in range(121):
    # grid.add_widget(Label(text=str(i)))


    graApp().run()


    kv:

    BoxLayout:
    [...]

    GridLayout:
    id: 'board'
    cols: 11
    [...]


    Error:

    grid = layout.ids['board']
    ~~~~~~~~~~^^^^^^^^^
    KeyError: 'board'


    Thanks in advance for your help

    Continue reading...

Compartilhe esta Página