Search code examples
pythonanimationpygtkgobject

Motion Animation


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.


Solution

  • 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.

    def fishmove():
       global fishmove
       if fishmove < 640:
            fishmove = fishmove + 10
            fixed_hab.move(fish1, fishmove, 50)  
            return True
    
    gobject.timeout_add(1, fishmove)