I am building a Sudoku game. Board is a 2D array of digits from 0 to 9 where 0 is an empty space. I have trouble displaying my board with Pygame. When I select a square on the board with digit 5 and enter a new digit 7 Pygame is suppose to just display newly entered digit instead of the previous one. But instead it displays the new digit over the previous digit (like on the picture). Backend works perfectly meaning that e.g. when I enter 7, it substitutes 7 for 5 on my 2D array board. But for some reason it doesn't display correctly on the screen. My chunk of code responsible for drawing is below including the picture.
P.S. I tried functions pygame.event.pump() and pygame.display.flip() but nothing helps.
while game_running:
......code dealing with events........
for r in range(9):
for c in range(9):
#draw small rectangle
sm_rect = pygame.Rect(c*sm_rect_width, r*sm_rect_height, sm_rect_width, sm_rect_height)
pygame.draw.rect(game_window, (0,0,0), sm_rect, 1)
#draw large rectangle if it is time
if r%3 == 0 and c%3 == 0:
lrg_rect = pygame.Rect(c/3*lrg_rect_width, r/3*lrg_rect_height, lrg_rect_width, lrg_rect_height)
pygame.draw.rect(game_window, (0,0,0), lrg_rect, 3)
#draw number
#Render text
if board[r][c] == 0:
txt_surface = font.render(" ", True, pygame.Color('dodgerblue2'))
game_window.blit(txt_surface, (c*sm_rect_width+17, r*sm_rect_height+15))
if board[r][c] > 0:
txt_surface = font.render(str(board[r][c]), True, pygame.Color('dodgerblue2'))
game_window.blit(txt_surface, (c*sm_rect_width+17, r*sm_rect_height+15))
pygame.display.update()