python - how to pass info from one widget to another in kv kivy -


i want set text of label when button pressed, problem being son separate screens , therefore in separate widgets in kv file. code have change is:

<screenone>:     boxlayout:         textinput:             id: player_name          button:             text: "continue"             on_release:                 root.manager.current = "screen2"                 root.ids.final_playername.text=player_name.text <screentwo>:     gridlayout:             label:                 text: "player"                 id: final_playername 

the error is:

traceback (most recent call last):    file "c:\users\rayne\desktop\python exp\noughts , crosses kivy sm\nandx.py", line 36, in <module>      nandxapp().run()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\app.py", line 828, in run      runtouchapp()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\base.py", line 504, in runtouchapp      eventloop.window.mainloop()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop      self._mainloop()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 405, in _mainloop      eventloop.idle()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\base.py", line 342, in idle      self.dispatch_input()    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\base.py", line 327, in dispatch_input      post_dispatch_input(*pop(0))    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\base.py", line 293, in post_dispatch_input      wid.dispatch('on_touch_up', me)    file "kivy\_event.pyx", line 718, in kivy._event.eventdispatcher.dispatch (kivy\_event.c:8191)    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\behaviors\button.py", line 179, in on_touch_up      self.dispatch('on_release')    file "kivy\_event.pyx", line 714, in kivy._event.eventdispatcher.dispatch (kivy\_event.c:8146)    file "kivy\_event.pyx", line 1225, in kivy._event.eventobservers.dispatch (kivy\_event.c:14035)    file "kivy\_event.pyx", line 1109, in kivy._event.eventobservers._dispatch (kivy\_event.c:12816)    file "c:\users\rayne\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 64, in custom_callback      exec(__kvlang__.co_value, idmap)    file "c:\users\rayne\desktop\python exp\noughts , crosses kivy sm\nandx.kv", line 51, in <module>      root.ids.final_playername.text=player_name.text    file "kivy\properties.pyx", line 839, in kivy.properties.observabledict.__getattr__ (kivy\properties.c:12654)  attributeerror: 'super' object has no attribute '__getattr__' 

in .py file have minimum classes screens, i´m trying keep simple under advice , in kv file. can newbie python learner set up? thank you

please refer snippet , example below details.

snippet

button:     size_hint: (.2, .08)     text: "continue"     on_release:         root.manager.ids.screen_two.ids.final_playername.text = player_name.text         root.manager.current = "screen2" 

example

nandxapp.py

from kivy.app import app kivy.uix.widget import widget kivy.uix.screenmanager import screenmanager, screen kivy.config import config  config.set("graphics", "width", "400") config.set("graphics", "height", "570") config.set("graphics", "borderless", "0") config.set("graphics", "resizable", "0") config.set("kivy", "window_icon", "nyc.ico")   class manager(screenmanager):     pass   class screenone(screen, widget):     pass   class screentwo(screen, widget):     pass   class screenthree(screen):     pass   class nandxapp(app):     def build(self):         self.title = "noughts , crosses"         return manager()   if __name__ == "__main__":     nandxapp().run() 

nandx.kv

#:kivy 1.10.0  <manager>:     screenone:         id: screen_one      screentwo:         id: screen_two      screenthree:         id: screen_three  <screenone>:     name: "screen1"     gridlayout:         size_hint: (.5, .5)         pos_hint: {"center_x":0.5,"center_y":0.6}         rows: 3         padding: 20          label:             size_hint: (.2, .2)             text: "please enter\nyour name:"             font_size: 30             halign: 'center'             valign: 'middle'          textinput:             size_hint: (.2, .06)             cursor_blink: true             font_size: 20             multiline: 0             id: player_name          button:             size_hint: (.2, .08)             text: "continue"             on_release:                 root.manager.ids.screen_two.ids.final_playername.text = player_name.text                 root.manager.current = "screen2"  <screentwo>:     name: "screen2"     gridlayout:         cols: 3         size: root.size         spacing: 10         padding: 10          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("topleft")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("topmiddle")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("topright")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("centerleft")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("centermiddle")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("centerright")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("bottomleft")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("bottommiddle")          button:             background_normal: ("blank.png")             # on_release: root.methodforbuttonpress ("bottomright")          button:             background_normal: ("x.png")          gridlayout:             rows: 2              label:                 text: "top label"              label:                 text: "bottom label"          button:             background_normal: ("circle.png")          gridlayout:             rows: 2              label:                 text: "player"                 id: final_playername              label:                 text: "score:"          label:             text: ""          gridlayout:             rows: 2              label:                 text: "computer"              label:                 text: "score:"   <screenthree>:     name: "screen3" 

output

screen2 player's name


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -