Help animating shrinking button width from both sides. [Code snippet inside].

48 views
Skip to first unread message

jetpack

unread,
Jun 2, 2015, 12:01:25 AM6/2/15
to kivy-...@googlegroups.com
Im trying to shrink button width from both sides but cant seem to figure out how. Here's few examples of what i've tried nothing worked. Some insight would be appreciated. Thanks.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.base import runTouchApp
from kivy.properties import ObjectProperty
from kivy.animation import Animation

Builder.load_string('''

<SampleRoot>:
orientation:'vertical'
Button:
size_hint:None,None
size:300,100
pos_hint:{'x':.2}
on_press:root.do_stuff(self)

''')


class SampleRoot(BoxLayout):

butto=ObjectProperty()

def do_stuff(self,butt):
self.butto=butt
# anim=Animation(x=400) + Animation(size=(30,100)) # doesn't work
# anim=Animation(x=400,size=(30,100)) # doesn't work either

# anim=Animation(x=400)
anim=Animation(size=(30,100)) # doesnt work either

anim.start(butt)
anim.bind(on_progress=self.do_more)

def do_more(self,*args,**kwargs):
print "ha"
anim=Animation(right=400)
anim.start(self.butto)




runTouchApp(SampleRoot())

ZenCODE

unread,
Jun 2, 2015, 2:56:48 AM6/2/15
to kivy-...@googlegroups.com
The trick here is to use the 'center' properties. So,change the buttons pos hint to:

    pos_hint:{'center_x': 0.5}

An issue might be that it's contained in a BoxLayout, which tries to make widgets occupy all its space. For things like moving and resizing, I think a FloatLayout might be easier to use? The allows freeform moving and sizing.

Hope that helps?



jetpack

unread,
Jun 2, 2015, 10:09:39 AM6/2/15
to kivy-...@googlegroups.com
Hey thanks , using center property solved the problem on boxlayout itself. You're right about Floatlayout though but I'm animating many buttons on a scroll view So, I figured box or grid layout would be feasible. Thanks again.
Reply all
Reply to author
Forward
0 new messages