我正在尝试使用屏幕上的按钮行为为图像设置动画。我使用完全相同的代码(至少对于动画部分)让动画工作,所以我假设动画的代码做了我想要它做的事情,但在做了一些改变之后它不再有效。单击时调用self.to_menu()但不进行动画。我做错了什么?
start_screen.py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.base import runTouchApp
from kivy.uix.floatlayout import FloatLayout
from kivy.clock import Clock
from functools import partial
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivy.animation import Animation
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.lang import Builder
import time
presentation = Builder.load_file("test.kv")
def set_color(button, color, *args):
button.color = color
class PStartButton(ButtonBehavior, Image, Widget):
def __init__(self, **kwargs):
super(PStartButton, self).__init__(**kwargs)
#Clock.schedule_interval(self.reset_color, 3)
def reset_color(self, *args):
Clock.schedule_once(partial(set_color, self, (1,1,1,1)),1)
Clock.schedule_once(partial(set_color, self, (0,1,0,1)),2)
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
Clock.unschedule(self.reset_color)
self.to_menu()
#def on_touch_up(self, touch):
#if self.collide_point(*touch.pos):
#if touch.grab_current is self:
#self.to_menu()
#return True
def to_menu(self):
#sb=self.ids.pstart_button
anim = Animation(pos =(Window.width * .05, Window.height *.60))
anim &= Animation(size =(Window.width * .15, Window.height * .15))
anim.start(self)
class StartScreen(FloatLayout):
pass
#def __init__(self, **kwargs):
#super(StartScreen, self).__init__(**kwargs)
runTouchApp(StartScreen())
test.kv
#:kivy 1.9
<StartScreen>:
orientation: 'horizontal'
size: root.size
canvas.before:
Rectangle:
pos:self.pos
size: self.size
source: 'bg.png'
FloatLayout:
PStartButton:
id:pstart_button
pos: root.center_x - (self.width/2), root.center_y - (self.height/2)
<FloatLayout>:
orientation: 'horizontal'
<PStartButton>:
size_hint: (.30,.30)
source: 'start_button.png'