why kivy ids dictionary become empty ?

24 views
Skip to first unread message

Degenerate Tech

unread,
Apr 19, 2024, 4:24:14 AMApr 19
to Kivy users support
python==3.10.12
Kivy ==v2.3.0
kivymd== 2.0.1.dev0

from kivy.lang import Builder
from kivymd.uix.screen import MDScreen
from kivymd.uix.screenmanager import MDScreenManager
from kivymd.app import MDApp
from kivy.clock import Clock
KV = '''
SM:
    MDScreenManager:
        id:sm

<MScreen>:
    md_bg_color: self.theme_cls.backgroundColor

    MDScrollView:

        MDBoxLayout:
            orientation: "vertical"
            spacing: "20dp"
            adaptive_height: True
            size_hint_x: .8
            pos_hint: {"center_x": .5, "center_y": .5}

            MDTextField:
                mode: "filled"
                radius:'25dp'
                MDTextFieldLeadingIcon:
                    icon: "magnify"
                    theme_icon_color: "Custom"
                    icon_color_normal: "lightgreen"

                MDTextFieldHintText:
                    text:"Search..."
                MDTextFieldTrailingIcon:
                    icon: "information"
            MDTextField:
                mode: "filled"
                radius:'25dp'
                MDTextFieldLeadingIcon:
                    icon: "magnify"
                    theme_icon_color: "Custom"
                    icon_color_normal: "lightgreen"

                MDTextFieldHintText:
                    text:"Search..."
                MDTextFieldTrailingIcon:
                    icon: "information"

           

       
'''

class SM(MDScreen):
    def __init__(self,*args,**kargs):
        super().__init__(*args,**kargs)
    def on_kv_post(self,obj):
        print("##",self.ids)

        #self.ids.sm.add_widget(MScreen())

class MScreen(MDScreen):pass


class Example(MDApp):
    def build(self):
        self.theme_cls.primary_palette = "Olive"
        Builder.load_string(KV)
        return SM()



Example().run()

elli...@cox.net

unread,
Apr 19, 2024, 4:37:45 PMApr 19
to Kivy users support
Change your app class as below:

class Example(MDApp):
   
def build(self):
       
self.theme_cls.primary_palette =
"Olive"
       
return Builder.load_string(KV)

You were declaring a root widget in both python and kv.

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Degenerate Tech <sksah...@gmail.com>
Sent: Friday, April 19, 2024 1:24 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] why kivy ids dictionary become empty ?
 
--
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/da73d93e-7dd4-40aa-abfa-9a8f4c71cf70n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages