2017-12-12 1 views
0

저는 파이썬에서 스크립트를 가지고 있고 다른 화면에서 kivy 파일을 가지고 있습니다. 화면 1에서는 TextInput에 몇 가지 정보를 소개하고 다음 화면 (화면 2)으로 변경할 때 화면 1의 TextInput에서 소개하는 변수의 값을 복구하려고합니다. 기능의 값을 업데이트하는 데 문제가 있습니다. 화면의 __init__ 2.화면을 바꿀 때 화면 값을 어떻게 업데이트 할 수 있습니까?

자동으로 값을 업데이트하는 가장 좋은 방법은 무엇인지 모르겠습니다.

class PantallaDos(Screen): 

    def __init__(self, *args): 
     super(PantallaDos, self).__init__(**kwargs) 
     softinput_mode = 'below_target' 
     Window.softinput_mode = softinput_mode 

     self.ids['pol'].text = 'verdadero' 

Kivy의 kv.file

<PantallaDos>: 

    BoxLayout: 
     orientation: 'vertical' 
     padding: 10 
     spacing: 3 
     canvas: 
      Color: 
       rgb: 0.15,0.14,0.14 
      Rectangle: 
       pos: self.pos 
       size: self.size 

.... 

     SLabel: 
      id: pol 
      size_hint: None, None 
      size: root.width, 30 

답변

0

당신은에 ScreenManager 클래스의 공유 데이터를 저장하거나 forexample 앱 클래스 수 있습니다.
아니면 그냥 kv에서 직접 액세스하십시오.
다음은 kv에서 textinput의 id를 사용하여 다른 화면에서 레이블 텍스트를 설정하는 예제입니다.

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


Builder.load_string(""" 

<Manager>: 
    Screen: 
     name: 'first' 
     BoxLayout: 
      TextInput: 
       id: ti 
       text: 'type something' 
      Button: 
       text:'go to other' 
       on_press: app.sm.current = 'other' 

    Screen: 
     name: 'other' 
     BoxLayout: 
      Label: 
       text: ti.text 
      Button: 
       text:'go to first' 
       on_press: app.sm.current = 'first' 

""") 


class Manager(ScreenManager): 
    pass 


class ClassApp(App): 

    def build(self): 
     self.sm = Manager() 
     return self.sm 


if __name__ == '__main__': 
    ClassApp().run() 
+0

위대한 !! 고마워. – JCAguilar

관련 문제