Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy error: raise FactoryException('Unknown class <%s>' % name)

Tags:

python

kivy

I have searched and searched, and i just don´t get it. From what i understand from posted answers, the problem is the class is not defined or spelled badly, but i have gone back and forth through my code and i can´t see the problem. Right now i´m just trying to get the layout there is no funcionality. I have two files, the .py and the .kv file, the main .py is:

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button


class Noughtsandcrosses(Widget):
    pass


class nandxApp(App):
    def build(self):
        return Noughtsandcrosses()

if __name__ == "__main__":
    nandxApp().run()

and the .kv file is:

#:kivy 1.0

<Noughtsandcrosses>:
    orientation: 'vertical'
    size: self.size

    Threebythreeone:
        orientation: 'horizontal'

        Button:
            Image:
                source: "blank.png"
                size: 100, 100

running the .py file this is the error i get:

Traceback (most recent call last):
   File "nandx.py", line 24, in <module>
     nandxApp().run()
   File "C:\Users\Rayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "nandx.py", line 21, in build
     return Noughtsandcrosses()
   File "C:\Users\Rayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\widget.py", line 345, in __init__
     Builder.apply(self, ignored_consts=self._kwargs_applied_init)
   File "C:\Users\Rayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\lang\builder.py", line 451, in apply
     self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts)
   File "C:\Users\Rayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\lang\builder.py", line 526, in _apply_rule
     cls = Factory_get(cname)
   File "C:\Users\Rayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\factory.py", line 131, in __getattr__
     raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <Threebythreeone>

i´m trying hard to learn kivy but it´s so frustrating getting a random error like this, can anyone point out what i´ve done wrong please.

like image 954
Rayne Avatar asked Sep 08 '17 22:09

Rayne


1 Answers

You encountered the error, kivy.factory.FactoryException: Unknown class <Threebythreeone> because you have a child widget Threebythreeone in the <Noughtsandcrosses> widget rule, nandx.kv

I recommend that you check out Programming Guide » Kivy Basics and the example below.

Example

main.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class Threebythreeone(BoxLayout):
    pass


class Noughtsandcrosses(BoxLayout):
    pass


class nandxApp(App):
    def build(self):
        return Noughtsandcrosses()


if __name__ == "__main__":
    nandxApp().run()

nandx.kv

#:kivy 1.10.0

<Threebythreeone>:
    # orientation: 'horizontal'   # Commented off because this is the default

    Button:
        Image:
            source: "blank.png"
            size: 100, 100

<Noughtsandcrosses>:
    orientation: 'vertical'
    size: self.size

    Threebythreeone:

Output

enter image description here

like image 53
ikolim Avatar answered Nov 07 '22 18:11

ikolim