I'm new to programming in Python. About three weeks ago I finished a Tetris clone using the turtle module to test my skills. I was under the impression that when I turned off the animation tracer, I had to manually update the window with the update()
method. Yesterday, while coding a snake clone with the turtle module, I had to explain to a friend why I was manually updating the screen. For proof, I opened Tetris and commented out the update()
methods to show that the game would not work. To my surprise, it actually worked and I can't get my head around how it did as even my snake code would not work without the update()
method.
Here is a part of the main loop of the Tetris code:
while not game_over:
if not current_piece.does_piece_fit(starting_row + 2, starting_column, current_piece.current_piece):
game_over = True
wn.update()
movement()
marco.update_grid()
marco_next.show_next_piece(next_piece)
show_score()
current_piece.proyeccion()
marco_next.show_text(x_text_next_piece, y_text_next_piece, "Next Piece:", normal_style)
marco_next.show_text(x_text_hold, y_text_hold, "Hold:", normal_style)
show_instructions(x_text_instructions, y_text_instructions, instructions_text, smaller_style)
if holding:
marco_hold.show_hold_piece(hold_piece)
If the wn.update()
line is commented out, it shouldn't work, but somehow it does. The code is a bit lengthy and I'm new on this site so I don't know if posting it entirely might be considered bad or rude on my part. Thanks for reading this, sorry for the bad english and messy code.
update()
. Or maybe there are some functions with may force turtle to redraw screen. For exampleupdate_grid()
– Crampton