Advertisement
obernardovieira

[Kivy] Enable/Disable Button

Jul 22nd, 2016
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # Special thanks to toto_tico
  2. # http://stackoverflow.com/a/19881645
  3.  
  4. from kivy.uix.button import Button
  5. from kivy.properties import BooleanProperty
  6.  
  7. class ButtonEx(Button):
  8.     enabled = BooleanProperty(True)
  9.  
  10.     def on_enabled(self, instance, value):
  11.         if value:
  12.             self.background_color = [1,1,1,1]
  13.             self.color = [1,1,1,1]
  14.         else:
  15.             self.background_color = [1,1,1,.3]
  16.             self.color = [1,1,1,.5]
  17.  
  18.     def on_touch_down( self, touch ):
  19.         if self.enabled:
  20.             return super(self.__class__, self).on_touch_down(touch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement