Python for kivy:Pass values between multiple screens -
i developing kivy app in ,there 2 screens 1.loginscreen , 2.homescreen.
what required - value 'xyz' computed in class loginscreen
, passed method 'insertdata'
of class homescreen
, want display value on label.
for tried following code:
#!/usr/bin/env python # -*- coding: utf-8 -*- kivy.app import app kivy.uix.label import label kivy.uix.boxlayout import boxlayout kivy.uix.screenmanager import screen, screenmanager class loginscreen(screen): def __init__(self,**kwargs): super(homescreen, self).__init__(**kwargs) def auth(self): xyz=1 self.manager.current="home" obj=homescreen() # 1. pass 'xyz' method scrn2 homescreen.insertdata(obj) class homescreen(screen): def __init__(self,**kwargs): super(loginscreen, self).__init__(**kwargs) if (a==1): # 2. display label self.scrn2() def insertdata(self): print "screen 2" label=label(text="good moring") self.add_widget(label) class screenapp(app): pass if __name__ == '__main__': screenapp().run()
here:
- insertdata called method auth
1)the 1st way proper , passing 'xyz' , calling method insertdata
dosen't display label
2) in 1st way have create create object of homescreen ,to call insertdata
, in turn calls ___init__
of homescreen
, init
calls insertdata
- insertdata called __init__
1) loads data before user authentication @ loginscreen
insertdata
gets total 3 calls, affecting app launch time.
suggest me simple , effective way this. in advance.
you can use screen.manager()
method manager object 1 screen, use retrieve 1 screenmanager.get_screen()
method , pass value directly. working example check answer of question: kivy - slider class value change on screen
Comments
Post a Comment