jonwright / pyopengltk

OpenGL frame for Python/Tkinter via ctypes and pyopengl
MIT License
52 stars 14 forks source link

Animation not stopping when variable = False. it prints false but the animation does not stop. #23

Closed ShaunKulesa closed 3 years ago

ShaunKulesa commented 3 years ago

while self.runv == True: self.app.animate = 1 self.app.after(100, self.app.printContext) self.app.mainloop() else: print("false") self.app.animate = 0 self.app.after(100, self.app.printContext) self.app.mainloop()

ShaunKulesa commented 3 years ago

updated code but animation still carrying on. and yes the loop does work. it prints true and false when needed.

while self.runv == True:
      print("true")
      self.app.animate = 1
     self.app.after(100, self.app.printContext)
     self.app.mainloop()

print("false")
self.runv = False
self.app.animate = 0
self.app.after(100, self.app.printContext)
self.app.mainloop()
ShaunKulesa commented 3 years ago

I have a feeling its because you cant animate and stop animating mid way through running a program.

einarf commented 3 years ago

Use markdown code blocks 😄 : https://docs.github.com/en/free-pro-team@latest/github/writing-on-github/creating-and-highlighting-code-blocks

ShaunKulesa commented 3 years ago

@einarf i swear that wasn't working earlier, now that i formatted it is it easier to understand my issue?

jonwright commented 3 years ago

How are you updating the variable after you called mainloop? Usually there needs to be a callback from the gui loop. E.g. when does it know to start and stop animation?

ShaunKulesa commented 3 years ago

I add a function to a button to update self.runv. I'll upload my code to a github.

ShaunKulesa commented 3 years ago

https://github.com/ShaunKulesa/Shaun-Engine/tree/main

jonwright commented 3 years ago

I sent you a pull request. You need to call tkExpose or _display to trigger the animate loop.

ShaunKulesa commented 3 years ago

Thank you so much, you are a great person.

ShaunKulesa commented 3 years ago

@jonwright i see this has tk.expose, are all of the things on here relevant? http://pyopengl.sourceforge.net/pydoc/OpenGL.Tk.html

jonwright commented 3 years ago

This code was written to avoid needing to recompile togl. Hopefully this is vaguely compatible, most of the code comes from there.

ShaunKulesa commented 3 years ago

@jonwright what method would i use to reset an animation?

ShaunKulesa commented 3 years ago

nothing on here works except "keys" which returned nothing, http://pyopengl.sourceforge.net/pydoc/OpenGL.Tk.html.