kivy ids problem

21 views
Skip to first unread message

Degenerate Tech

unread,
Dec 8, 2020, 3:52:14 AM12/8/20
to Kivy users support
class Root2(Screen):
def __init__(self,**k):
super().__init__(**k)
for i in range(20):
print(self.ids)
#add_widget(Plate(nav_drawer=self.ids.nav_drawer,grp=str(i),sname=str(i)))
def on_kv_post(self,obj):
for i in range(20):
print(obj.ids)
#.smr2.add_widget(Plate(nav_drawer=obj.ids.nav_drawer,grp=str(i),sname=str(i)))



class MainRoot(MDScreen):
pass

class PhysicsExam(MDApp):
def build(self):
return MainRoot()






<MainRoot>:
ScreenManager:
First:
Root2:

<Root2>:
    MDNavigationLayout:

        ScreenManager:
        id:smr2

            


        MDNavigationDrawer:
            id: nav_drawer




############## i am printing ids of Root2 but no ids are there

[INFO   ] [GL          ] NPOT texture support is available
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
[INFO   ] [Base        ] Start application main loop
[INFO   ] [WindowSDL   ] exiting mainloop and closing.
[INFO   ] [Base        ] Leaving application in progress...


Elliot Garbus

unread,
Dec 8, 2020, 9:14:17 AM12/8/20
to kivy-...@googlegroups.com

The ids are not set at the time __init__ executes. 

The method on_kv_post is passed the base_widget, in this case MainRoot.

In kv, the root widget (there is no root widget defined in the kv in this example), and each rule have their own ids dict.

 

Try the example below:

The output:

{'sm': <WeakProxy to <kivy.uix.screenmanager.ScreenManager object at 0x0457D6F8>>, 'first_screen': <WeakProxy to <Screen name=''>>, 'root2_screen': <WeakProxy to <Screen name=''>>}

{'smr2': <WeakProxy to <kivy.uix.screenmanager.ScreenManager object at 0x09F788F0>>, 'nav_drawer': <WeakProxy to <kivy.uix.button.Button object at 0x09F9C2D0>>}

 

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen

kv =
"""
<First@Screen>:

<MainRoot>:
    ScreenManager:
        id: sm
        First:
            id: first_screen
        Root2:
            id: root2_screen
           

<Root2>:
    BoxLayout:
        ScreenManager:
            id:smr2
        Button:
            id: nav_drawer
"""
Builder.load_string(kv)


class Root2(Screen):
   
def on_kv_post(self, obj):
       
print(obj.ids)
       
print(self.ids)


class MainRoot(Screen):
   
pass


class
PhysicsExam(App):
   
def build(self):
       
return MainRoot()


PhysicsExam().run()

--
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/e22bb1d3-43d2-47f0-8d6b-38a1e99bb530o%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages