Set text in TextInput

30 views
Skip to first unread message

хз кто

unread,
Oct 9, 2017, 8:49:21 AM10/9/17
to kivy-...@googlegroups.com
How to make this code work? 
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()

ZenCODE

unread,
Oct 9, 2017, 7:57:50 PM10/9/17
to Kivy users support
Try

    sm.current_screen.ids.ab.text = "Test"

You may need to add,

    class Two(Screen):
        ab = StringProperty('')

werton

unread,
Oct 13, 2017, 12:44:32 AM10/13/17
to Kivy users support
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()



понедельник, 9 октября 2017 г., 21:49:21 UTC+9 пользователь хз кто написал:
Reply all
Reply to author
Forward
0 new messages