Change button text value for on_press event in Kivy -


my application has single button text value '2'. want change text value 100 on on_press event

my attempt:

#!/usr/bin/kivy import kivy kivy.require('1.7.2')  random import random random import choice kivy.app import app kivy.lang import builder kivy.uix.screenmanager import screenmanager, screen kivy.uix.gridlayout import gridlayout kivy.uix.button import button  r1c2=random() builder.load_string(""" <highest>:     r1c2: str(2)     gridlayout:         cols: 1         button:             text: root.r1c2             on_press: root.new() """)  class highest(screen):     def new(self):         r1c2=str(100)   # create screen manager sm = screenmanager() sm.add_widget(highest(name='highest'))  class testapp(app):      def build(self):         return sm  if __name__ == '__main__':     testapp().run() 

error: currently, nothing happens when button pressed. please help

you should using kivy properties available. see kivy.properties more information.

add import access string property:

from kivy.properties import stringproperty 

and highest class should be:

class highest(screen):     r1c2 = stringproperty(str(2))      def new(self):         self.r1c2 = str(100) 

at initialization r1c2 value equal '2'. when function new() called value of r1c2 become '100'. button text bind string property r1c2 automatically change.

you don't need r1c2=str(2) in builder string.

builder.load_string(""" <highest>:     gridlayout:         cols: 1         button:             text: root.r1c2             on_press: root.new() """) 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -