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.

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130

2 Answers2

2

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.

Johannes Charra
  • 29,455
  • 6
  • 42
  • 51
  • Thank you, I'm sure that will help some, however the animation still isn't running. :( – CodeMouse92 Sep 18 '11 at 15:19
  • Maybe the problem is that the timeout is in milliseconds? That would finish the animation after 64 ms ... so it may well be that it's so fast you just don't perceive the animation. Try `gobject.timeout_add(50, fish_move)` and play around with the first param. – Johannes Charra Sep 18 '11 at 15:28
  • Nope, it distinctly stays in the same place that it starts at. Absolutely no movement. – CodeMouse92 Sep 18 '11 at 15:37
  • Interesting ... can you provide the updated code, and maybe an explanation what `fixed_hab.move` does? – Johannes Charra Sep 18 '11 at 16:51
  • I tested it out. fixed_hab.move does exactly what it is supposed to do. Also, I ensured that fishmove is changing in value. However, I determined via "print fishmove" in the function that g.object.timeout_add isn't calling the process more than once. – CodeMouse92 Sep 18 '11 at 18:28
1

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)
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130