【发布时间】:2019-09-25 06:50:49
【问题描述】:
我想要一个小部件随动画功能一起移动,而不是使用 pos,我想使用 pos_hint,因为它简化了很多事情。动画开始时,出于某种原因,它会将 pos_hint 设置为空 {}。我认为这与将 pos_hint 正确绑定到按钮有关,或者 anim 没有正确发送 pos_hint 值。
我已经尝试使用 pos 并且效果很好。
from kivy.graphics import *
from kivy.uix.floatlayout import FloatLayout
from kivy.animation import *
from kivy.lang.builder import Builder
Builder.load_string("""
<FloatLayout>:
button:
size_hint: 1,1/4
pos_hint: {'center_y':0.5,'right':0}
canvas:
Color:
rgba: [1,0,1,1]
Rectangle:
pos: self.pos
size: self.size
""")
class button(FloatLayout):
def __init__(self, **kwargs):
super(ButtonSr, self).__init__(**kwargs)
def checkpos(inst,val):
print(val) #prints {} as soon as self.startanim() is fired and
nothing else. pos_hint stays as {}
self.bind(pos_hint=checkpos)
self.startanim()
def startanim(self):
anim = Animation(pos_hint={'center_x':0.5},d=2)
anim.start(self)
我希望按钮从屏幕外移动到所选的 pos_hint
【问题讨论】: