运动动画
我有一个使用 Python 2.7 和 PyGTK 2.24 的项目。我使用以下代码在 gtk.Fixed 内创建 gtk.Image 的运动动画。
def fishmove():
global fishmove
if fishmove < 640:
fishmove = fishmove + 10
fixed_hab.move(fish1, fishmove, 50)
gobject.timeout_add(1, fishmove)
然而,虽然程序运行时没有抛出任何错误,但图像却没有移动。到底是怎么回事?
顺便说一句,fishmove 是从 0 开始的。
I have a project in Python 2.7 and PyGTK 2.24. I am using the following code to create a motion animation of a gtk.Image inside a gtk.Fixed.
def fishmove():
global fishmove
if fishmove < 640:
fishmove = fishmove + 10
fixed_hab.move(fish1, fishmove, 50)
gobject.timeout_add(1, fishmove)
However, while the program comes up without throwing any errors, the image doesn't move. What is going on?
BTW, fishmove starts out as 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意变量的命名!如果您有一个全局整数
fishmove
和一个同名的方法,那么这两个几乎肯定会以某种意想不到的方式进行干扰!尝试将该方法重命名为
move_fish
或其他。Pay attention to the naming of the variables! If you have a global integer
fishmove
and a method of the same name, those two will almost certainly interfere in some unexpected way!Try renaming the method to
move_fish
or sth.我解决了。我只需要在函数末尾添加“return True”行。这是固定代码。有用。
I solved it. I just needed to add the line "return True" at the end of the function. Here is the fixed code. It works.