Error: First letter of class name <classname> is in lowercase

391 views
Skip to first unread message

Hepha1st0s

unread,
Oct 20, 2022, 5:02:48 AM10/20/22
to Kivy users support
Hi everyone, 

I have started working with Kivy and have encountered the following problem:

No matter what I do, I always get the following error:
 
AttributeError: First letter of class name <<Menu>> is in lowercase

The code in the files looks like this:

MyApp.py:

import kivy
from kivy.app import App
from kivy.uix.widget import Widget

class Menu(Widget):
    pass

class MyApp(App):
    def build(self):
        return Menu()
   
if __name__ == "__main__":
    MyApp().run()


---------------------------------------------------------------------------------

my.kv:

<menu>:
    Label:
        text: "Hello World"


I have tried all possible upper-lower case variations but nothing works. Can someone please help me?

Elliot Garbus

unread,
Oct 20, 2022, 9:16:33 AM10/20/22
to kivy-...@googlegroups.com

<Menu>:
    Label:
        text: "Hello World"


The kv code in the <> needs to match the name of the python class definition.

 

As an aside, there is no reason in this case to put a label inside a Widget, a Label is derived frow a Widget.  Put widgets in Layouts.  The layouts position and size their child widgets.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d041f6e9-3af4-4c05-8912-fc4d5a297843n%40googlegroups.com.

 

Hepha1st0s

unread,
Oct 20, 2022, 1:13:06 PM10/20/22
to Kivy users support
Thank you for your reply. Unfortunately, I accidentally copied the wrong code into the my.kv file. The actual code is:

<Menu>
    text: "Hello World

So the name inside the <> and the class name matches, otherwise the case would be clear. I am a bit at a loss here :( 

Elliot Garbus

unread,
Oct 20, 2022, 1:24:07 PM10/20/22
to kivy-...@googlegroups.com

Try this:

 

from kivy.app import App
from kivy.uix.label import Label


class Menu(Label):
   
pass


class
MyApp(App):
   
def build(self):
       
return Menu()


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

 

my.kv:

<Menu>
    text: "Hello World"

Hepha1st0s

unread,
Oct 20, 2022, 1:30:10 PM10/20/22
to Kivy users support

I got the same error again. I even followed the tutorial on the kivy.org website (that pong game) and also got the stupid error.

Elliot Garbus

unread,
Oct 20, 2022, 1:31:59 PM10/20/22
to kivy-...@googlegroups.com

Do you have only one kv file in the directory?  The code I posted runs for me.

Hepha1st0s

unread,
Oct 20, 2022, 1:36:56 PM10/20/22
to Kivy users support
I have the solution. Apparently I am not allowed to create a KV file using VSC :D 

If I first create a .txt file and rename it, it works beautifully!

Now I'm relieved, thanks for your help!

Reply all
Reply to author
Forward
0 new messages