Dima  Kudosh
Dima Kudosh

Reputation: 7366

import widget in kivy file

I created some custom widget.

from kivy.uix.widget import Widget
from kivy.lang import Builder


class ExampleWidget(Widget):
     Builder.load_file("kv/example.kv")

kv/example.kv

#:kivy 1.9.1

<ExampleWidget>:
    Label:
        text: Example

Than I want to create another widget with example widget. Like this:

kv/second.kv

#:kivy 1.9.1

<SecondWidget>:
    ExampleWidget:

But I got this error

kivy.factory.FactoryException: Unknown class <ExampleWidget>

Kivy can't find my custom widget, so how I can import it to another kivy file?

Upvotes: 3

Views: 1793

Answers (1)

Nykakin
Nykakin

Reputation: 8747

You can import it using following syntax (assuming that ExampleWidget is defined in example.py file and you have __init__.py in your directory):

#: import ExampleWidget example.ExampleWidget

<SecondWidget>:
    ExampleWidget:

Described in the documentation.

Upvotes: 3

Related Questions