【发布时间】:2015-09-22 02:31:38
【问题描述】:
到目前为止,我已经编写了可以输出图像的代码。但是当我尝试对其进行动画处理时,我得到一个“构建需要 2 个参数。1 个给定”错误。
import kivy
from kivy.app import App
from kivy.uix.image import Image
from kivy.animation import Animation
from kivy.uix.widget import Widget
class TheApp(App):
def build(self):
image = Image(source= "psychTREE.jpg")
image.allow_stretch= True
image= TheApp.animation()
image.animate()
return image
def animation(self, instance):
animate = Animation(pos = (100, 100), t= "out_bounce")
animate += Animation(pos= (200, 100), t = "out_bounce")
animate &= Animation(size = (500, 500))
animate += Animation(size = (100, 50))
animate.start(instance)
if __name__ == "__main__":
TheApp().run()
任何有关如何修复此代码的建议或想法将不胜感激。我正在尝试为图像设置动画,使其在背景屏幕中左右上下移动。
【问题讨论】:
-
能把导致错误的代码标记得更简洁吗?您的代码中是否有任何部分有效?
-
另外,您确定需要其中的 &= 吗?期望的行为是什么?
-
我不需要其中的 &=,但它的存在是为了产生过渡效果。无论如何,我遇到问题的部分是
def build(self): ### ### image= TheApp.animation() image.animate() return image未绑定方法 animation() 必须使用 TheApp 实例作为第一个参数调用(而不是什么都没有),如果我添加:def build(self, animation)它返回:构建需要两个论据。一个给定的。” -
请在您的问题中澄清并提供复制问题所需的最少代码。另请注明您的kivy版本。
标签: python animation build kivy