title: How to change background color of button on press in kivy?
body: <p>My app has a single button with a default background color. I just want to change its background color to another color on <code>on_press</code> event. You may consider it similar to visited and non-visited hyperlinks of html ie when a linked is clicked, it changes its color.</p>
  
  <p>My attempt:</p>
  
  <pre><code>#!/usr/bin/kivy
  import kivy
  kivy.require('1.7.2')
  
  from random import random
  from random import choice
  from kivy.app import App
  from kivy.lang import Builder
  from kivy.uix.screenmanager import ScreenManager, Screen
  from kivy.uix.gridlayout import GridLayout
  from kivy.uix.button import Button
  from kivy.properties import StringProperty
  
  Builder.load_string("""
  &lt;Highest&gt;:
      GridLayout:
          cols: 1
          Button:
              text: "Hi"
              on_press: root.new()
  """)
  
  class Highest(Screen):
      def new(self):
          self.background_color=(1.0, 0.0, 0.0, 1.0)
  
  
  # Create the screen manager
  sm = ScreenManager()
  sm.add_widget(Highest(name='Highest'))
  
  class TestApp(App):
  
      def build(self):
          return sm
  
  if __name__ == '__main__':
      TestApp().run()
  </code></pre>
  
  <p>But nothing happens on on_press</p>
  
  <hr>
  
  <p>@inclement</p>
  
  <p>Actually, i tried to minimized my problem.</p>
  
  <p>What i actually need is to give different colors on different conditions based on a variable</p>
  
  <pre><code>class Highest(Screen):
      def new(self):
          if(a==5):
              self.background_color=(1.0, 0.0, 0.0, 1.0)
          else:
              self.background_color=(1.0, 1.0, 1.0, 1.0)
  </code></pre>
  
  <p>so i want impementation in my class Highest. Please guide. Thanks in advance.</p>