1

I have a program that uses turtle graphics. The problem is I have a game loop but don’t know where to put the mainloop function. If I put it before the game loop then game loop won't get executed. If I put it after mainloop will never get executed because the game loop is an infinite loop. Lastly if I put mainloop in game loops end than game loop will only get executed once. Where should I put mainloop?

import turtle
#some turtle code
while True:
  #some code

turtle.mainloop
1
  • You know, that while True is blocking forever? So no matter where you put it, all the code beneath it will not be reached. This is both true for the example you pasted as for the example where the loop is inside the mainloop. Commented Dec 9, 2019 at 11:50

1 Answer 1

1

If I put it after mainloop will never get executed because the game loop is an infinite loop. Lastly if I put mainloop in game loops end than game loop will only get executed once. Where should I put mainloop?

You should either use mainloop() and drive your game loop using e.g. ontimer() or an explicit game loop. Not both.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.