python - Changing Kivy widget attribute from another widget -
python - Changing Kivy widget attribute from another widget -
i have screen widget button (with id: display_name) has text attribute. when press button, modal displayed has text input widget , button widget. want come in text modal's text input widget , display text in screen widget's button when press modal's button. having difficulty changing screen button's text attribute modal. how do this? i've tried code below, error:
attributeerror: 'kivy.properties.objectproperty' object has no attribute 'text'
kv code
<profilescreen>: display_name: display_name generalboxlayout: boxlayout: gridlayout: backbutton: on_release: root.manager.current = 'home' size_hint: (0.1,1.0) image: size_hint: (0.1,1.0) image: source: 'img/logo4.png' size_hint: (0.60,1.0) image: size_hint: (0.05,1.0) menubutton: size_hint: (0.15,1.0) on_release: app.build_profile_screen(); root.manager.current = 'profile' boxlayout: scrollview: size_hint: (1,.93) gridlayout: boxlayout: button: id: display_name font_size: '14sp' text_size: (290, 40) halign: 'left' background_normal: 'img/white_button1.png' background_down: 'img/white_button1.png' border: 20,20,20,20 markup: true on_release: app.update_display_name_popup() <updatedisplaynamepopup>: updated_display_name: updated_display_name size_hint: .5, .3 boxlayout: padding: [10,10,10,10] orientation: 'vertical' textinput: id: updated_display_name hint_text: 'enter new display name' button: font_size: '14sp' text: 'update display name' background_normal: 'img/green_button5.png' background_down: 'img/green_button5.png' size_hint_y: none on_release: root.update_display_name(); root.dismiss()
main.py code
from kivy.properties import objectproperty class profilescreen(screen): display_name = objectproperty(none) class updatedisplaynamepopup(modalview): def update_display_name(self): profilescreen.display_name.text = self.updated_display_name.text
i solved moving update_display_name method profilescreen class, calling modal's button, , passing updated_display_name.text method, follows:
main.py
class profilescreen(screen): def update_display_name(self, updated_display_name): self.display_name.text = updated_display_name
kv file
button: on_release: app.root.get_screen('profile').update_display_name(updated_display_name.text); root.dismiss()
python python-2.7 kivy
Comments
Post a Comment