Animating size of image - not working

200 views
Skip to first unread message

Ricardo Couto

unread,
May 18, 2015, 10:53:23 AM5/18/15
to kivy-...@googlegroups.com
Hello guys!

I'm trying to animate the size of an image, so that when I click a button the image increases it's size. My code is the following:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.animation import Animation

Builder.load_string("""
<MainScreen>:
    Button:
        on_release: root.animate_image()
        BoxLayout:
            orientation: "
vertical"
            size: self.parent.size
            pos: self.parent.pos
            BoxLayout:
                orientation: "
horizontal"
                size_hint_y: 0.3
            Image:
                id: img_anim
                source: "
image.png"
                size_hint_y: 0.4
                allow_stretch: True
                Label:
                    pos: self.parent.pos
                    size: self.parent.size
            BoxLayout:
                orientation: "
horizontal"
                size_hint_y: 0.3


"""
)

class MainScreen(Screen):
   
def animate_image(self):
        anim
= Animation(size=(500, 500), d=1.)
        anim
.start(self.ids["img_anim"])

sm
= ScreenManager()
sm
.add_widget(MainScreen(name='main'))

class MainApp(App):

   
def build(self):
        sm
.current = 'main'
       
return sm

if __name__ == '__main__':
   
MainApp().run()


This is not working. However, when I try to animate the image's position, it works. Why is that? Can you help me solve it? :)

Thanks!

ZenCODE

unread,
May 18, 2015, 3:49:31 PM5/18/15
to kivy-...@googlegroups.com
It's probably either/both the pos_hint, size_hint. It's also in a BoxLayout, which is much stricter than a FloatLayout for free resizing/moving. I would switch the Image's container to a FloatLayout and then animated the size_hint property rather than the size itself.

But I have no idea what you are doing, so feel free to ignore that. Try removing the size/pos hints from the image, or try putting it in a FloatLayout.

Cheers

Ricardo Couto

unread,
May 19, 2015, 6:15:50 AM5/19/15
to kivy-...@googlegroups.com
Thanks a lot ZenCODE!

Instead of animating the size, I animated the size_hint and it worked :)

Cheers

ZenCODE

unread,
May 19, 2015, 11:54:24 AM5/19/15
to kivy-...@googlegroups.com
Awesome! :-)
Reply all
Reply to author
Forward
0 new messages