title: Changing image in widget - Kivy - Python
body: <pre><code>from kivy.app import App
  from kivy.uix.widget import Widget
  from kivy.uix.button import Button
  from kivy.graphics import Color, Rectangle
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.floatlayout import FloatLayout
  from kivy.uix.image import Image
  
  class Imglayout(FloatLayout):
  
      def __init__(self,**args):
          super(Imglayout,self).__init__(**args)
  
          with self.canvas.before:
              Color(0,0,0,0)
              self.rect=Rectangle(size=self.size,pos=self.pos)
  
          self.bind(size=self.updates,pos=self.updates)
      def updates(self,instance,value):
          self.rect.size=instance.size
          self.rect.pos=instance.pos
  
  
  class MainTApp(App):
  
      im=Image(source='img1.jpg')
      def build(self):
          root = BoxLayout(orientation='vertical')
          c = Imglayout()
          root.add_widget(c)
  
  
          self.im.keep_ratio= False
          self.im.allow_stretch = True        
          cat=Button(text="Categories",size_hint=(1,.07))
          cat.bind(on_press=self.callback)        
          c.add_widget(self.im)
          root.add_widget(cat);       
          return root
  
      def callback(self,value):
          self.im=Image(source='img2.jpg')
  
  
  if __name__ == '__main__':
      MainTApp().run()
  </code></pre>
  
  <p>What i am trying to do here, is change the image first loaded during object creation, which is shown when the app starts, and then change it when the button cat is pressed. I am trying it to do this way but it isnt happening. I would eventually want it to change with a swipe gesture.(with a little bit of swipe animation like it happens in the phone</p>
  
  <p>what i am trying to build is a slideshow, which will change image in t seconds, unless swiped, and then when a new image comes the timer resets. 
  When the category button is pressed the image will not be there and a list of categories to select from. and when an item from the list is touched the images from that list will be displayed on the screen.</p>
  
  <p>And at the end when everything has been done i would want to make it such that it automatically detects categories(based on directories in a specified location.) and then all the images will be available to it.(that is not telling it explicitly how many images and what images.)</p>
  
  <p>But, i am not able to do the first thing, so i would really like some help on that. And maybe a few pointers on how to achieve the other things as well.</p>