Upgrading from 1.11.1 to 2.1 breaks on ids

413 views
Skip to first unread message

zensku...@gmail.com

unread,
Apr 4, 2022, 4:57:32 PM4/4/22
to Kivy users support
Hi, I've got a pure python program and a .kv file. Just upgraded from 1.11.1 to 2.1 and it crashes when starting, throwing this exception:

####################
 Traceback (most recent call last):
   File "kivy\_event.pyx", line 235, in kivy._event.EventDispatcher.__init__
 TypeError: object.__init__() takes exactly one argument (the instance to initialize)

 The above exception was the direct cause of the following exception:

 Traceback (most recent call last):
   File "G:\GammaDev\src\gammaui.py", line 2366, in <module>
     GAMMAUIApp().run()
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\app.py", line 954, in run
     self._run_prepare()
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\app.py", line 924, in _run_prepare
     root = self.build()
   File "G:\GammaDev\src\gammaui.py", line 2359, in build
     main_screen = MainForm(name='main', id="main")
   File "G:\GammaDev\src\gammaui.py", line 85, in __init__
     super (MainForm, self).__init__(**kwargs)
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\uix\relativelayout.py", line 274, in __init__
     super(RelativeLayout, self).__init__(**kw)
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\uix\floatlayout.py", line 65, in __init__
     super(FloatLayout, self).__init__(**kwargs)
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\uix\layout.py", line 76, in __init__
     super(Layout, self).__init__(**kwargs)
   File "C:\Users\Tyler\AppData\Roaming\Python\Python39\site-packages\kivy\uix\widget.py", line 357, in __init__
     super(Widget, self).__init__(**kwargs)
   File "kivy\_event.pyx", line 238, in kivy._event.EventDispatcher.__init__
 TypeError: Properties ['id'] passed to __init__ may not be existing property names. Valid properties are ['center', 'center_x', 'center_y', 'children', 'cls', 'disabled', 'height', 'ids', 'manager', 'motion_filter', 'name', 'opacity', 'parent', 'pos', 'pos_hint', 'right', 'size', 'size_hint', 'size_hint_max', 'size_hint_max_x', 'size_hint_max_y', 'size_hint_min', 'size_hint_min_x', 'size_hint_min_y', 'size_hint_x', 'size_hint_y', 'top', 'transition_progress', 'transition_state', 'width', 'x', 'y']
####################

kv file looks like this
                Label:
                    id: visualization_label
                    pos: 50, root.height - 42
                    text_size: self.size
                    size_hint: None, None
                    size: 300, 22
                    markup: True
                    text: '[b]Visualization Options[/b]'
                    font_size: 20
                    halign: 'left'
                    orientation: 'horizontal'

My python is setup like this:
class MainForm(Screen):
    def __init__(self, **kwargs):
        super (MainForm, self).__init__(**kwargs)
        self.add_widget(MainScreen())

class MainScreen(Widget):
    def __init__(self, **kwargs):
        super (MainScreen, self).__init__(**kwargs)
        Window.size = (1100, 800)

        Clock.schedule_once(self._my_func1)
        Clock.schedule_once( self._my_func2 )

I read in the changelog that widget id's are no longer supported. Is that really the case and if so, how can I reference that label from code?

Thanks for any help!
Tyler

Elliot Garbus

unread,
Apr 4, 2022, 5:15:47 PM4/4/22
to kivy-...@googlegroups.com

You can reference a label from your code as you did through the ids dict.

Look to make sure in python you are not expecting that an id property was associated with a widget.

--
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/34c0c08d-5a64-455f-8b90-21a8868c648fn%40googlegroups.com.

 

zensku...@gmail.com

unread,
Apr 5, 2022, 7:47:56 AM4/5/22
to Kivy users support
If the widgets don't have id's, how can I reference them in code? For instance:
                Label:

                    pos: 50, root.height - 42
                    text_size: self.size
                    size_hint: None, None
                    size: 300, 22
                    markup: True
                    text: '[b]Visualization Options[/b]'
                    font_size: 20
                    halign: 'left'
                    orientation: 'horizontal'

How can I reference that in the ids dict, from code?

Elliot Garbus

unread,
Apr 5, 2022, 9:07:22 AM4/5/22
to kivy-...@googlegroups.com

The id is a kv construct, not a widget property.  See: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#ids

You put an id in kv, and when the kv is processed it creates an ids dictionary.

 

So you can do:

 

BoxLayout:

    Label:

        id: label_1

 

and access with widget in python using ids

 

You can not do:

Label(text=’Hello’, id=’WTF’)

Elliot Garbus

unread,
Apr 5, 2022, 9:12:12 AM4/5/22
to kivy-...@googlegroups.com

 

From: Elliot Garbus
Sent: Tuesday, April 5, 2022 6:07 AM
To: kivy-...@googlegroups.com
Subject: RE: [kivy-users] Upgrading from 1.11.1 to 2.1 breaks on ids

 

The id is a kv construct, not a widget property.  See: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#ids

You put an id in kv, and when the kv is processed it creates an ids dictionary.

 

So you can do:

 

BoxLayout:

    Label:

        id: label_1

 

and access with widget in python using ids

 

You can not do:

Label(text=’Hello’, id=’WTF’)

 

 

From: zensku...@gmail.com
Sent: Tuesday, April 5, 2022 4:48 AM

zensku...@gmail.com

unread,
Apr 5, 2022, 9:36:54 AM4/5/22
to Kivy users support
Got it. Thanks.

Reply all
Reply to author
Forward
0 new messages