import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
kivy.require('1.10.0')
Builder.load_string("""
<One>:
BoxLayout:
Button:
text: 'button'
on_press: root.button()
<Two>:
ab: ab
BoxLayout:
TextInput:
id: ab
"""
class One(Screen):
def button(self):
sm.current = 'two'
Two().ab.text = 'test' ''' <=== This does not work '''
class Two(Screen):
pass
sm = ScreenManager()
sm.add_widget(One(name='one'))
sm.add_widget(Two(name='two'))
sm.current = 'one'
class Main(App):
def build(self):
return sm
Main().run()
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
kivy.require('1.10.0')
Builder.load_string('''
<One>:
BoxLayout:
Button:
text: 'button
'
on_press: root.button()
<Two>:
ab: ab
BoxLayout:
TextInput:
id: ab
''')
class One(Screen):
def button(self):
sm.current = 'two'
#Two().ab.text = 'test' '''<=== This doesn't work because you create new instance of class Two, which is not added to the sm widget'''
sm.get_screen('two').ab.text = 'test'
class Two(Screen):
pass
sm = ScreenManager()
sm.add_widget(One(name='one'))
sm.add_widget(Two(name='two'))
sm.current = 'one'
class Main(App):
def build(self):
return sm
Main().run()