首页 > 代码库 > pyqt一个简单的动画
pyqt一个简单的动画
import sys
from PyQt4.QtGui import QApplication , QGraphicsEllipseItem , QGraphicsItemAnimation
from PyQt4.QtGui import QGraphicsScene , QGraphicsView
from PyQt4.QtCore import SIGNAL , QPointF , QTimeLine
app = QApplication( sys.argv )
# create a graphicsview with a moving ball...
ball = QGraphicsEllipseItem(0, 0, 20, 20)
timer = QTimeLine(5000)
timer.setFrameRange(0, 100)#帧计数器开始startFrame,结束
animation = QGraphicsItemAnimation()#提供了简单的动画支持
animation.setItem(ball)
animation.setTimeLine(timer)
for i in xrange( 200 ) :
animation.setPosAt(i / 200.0, QPointF(i, i))
scene = QGraphicsScene()
scene.setSceneRect(0, 0, 250, 250)
scene.addItem(ball)
view = QGraphicsView(scene)
view.show()
timer.start()
app.exec_()
如图:
链接:http://comments.gmane.org/gmane.comp.python.pyqt-pykde/15315
pyqt一个简单的动画