Reputation: 76
I am using KIVY Lib I want access some element in test class. How I should do it?
this is my code
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.floatlayout import FloatLayout
from kivy.lang.builder import Builder
test_helper ="""
MDLabel:
id : label
text: "Hello World !"
"""
class test(FloatLayout):
def __init__(self, **kwargs):
super(test, self).__init__(**kwargs)
self.add_widget(Builder.load_string(test_helper))
class MainApp(MDApp):
def build(self):
self.sm = ScreenManager()
self.test = test()
screen = Screen(name = "test")
screen.add_widget(self.test)
self.sm.add_widget(screen)
return self.sm
if __name__ == "__main__":
app = MainApp()
app.run()
for example I have MDlabel
in test_helper
who its for test class. but i do not know how access it
Upvotes: 1
Views: 252
Reputation: 29488
self.test = test()
With this declaration, you could access the MDLabel with self.test.children[0]
.
Upvotes: 1