there is no error message showing up thanks to Screen.mainloop
I'm not sure what you mean by this. My analysis of your code is you get the errors because instead of mainloop()
you use:
def play(self):
while True:
self.screen.update()
time.sleep(1/FPS)
...
PongGame().play()
Which really should be (re)structured more like:
def play(self):
...
self.screen.update()
ontimer(play, 1000/FPS)
PongGame().play()
screen.mainloop()
Loops like while True:
, and for that matter sleep()
, don't belong in an event-based environment like turtle as they can block events from being handled, which may trickle up to the user as errors.
Another thing in your code to (re)consider:
def __init__(self):
self.speed = 0
super().__init__(random.choice(BALL_ICONS))
speed()
is already a method of turtle, you're redefining it as a property. Calling super().__init__()
could have invoked a call to speed as a method. These statements should be the other way around and you should rename speed
to something like ball_speed
.