Frage

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.

War es hilfreich?

Lösung 2

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)

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top