How to print button text value on console in Kivy -


my app have 1 button , text random number 1 9. want print button text on console on on_press. actually, have minimized problem, want compare value variable, if button.text=5, else do_something_else.

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 kivy.properties import stringproperty  builder.load_string(""" <highest>:     gridlayout:         cols: 1         button:             text: root.r1c2             on_press: root.new() """)  class highest(screen):     r1c2 = stringproperty(str(int(random()*10)))     def new(self):         print self.text   # create screen manager sm = screenmanager() sm.add_widget(highest(name='highest'))  class testapp(app):      def build(self):         return sm  if __name__ == '__main__':     testapp().run() 

but gives error.

you don't error you're getting, 1 obvious problem self.text doesn't exit. calling on highest(screen), not button. access kv objects python tag them ids , use root_widget.ids.id_of_widget(see docs). alternative use kivy properties.

since have kivy property bound text of button, can print out:

print self.r1c1 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -