How can I prevent the only blocks from being clicked when I already have a block selected

I am making a video game in pygame, and this is just me practice the mouse mechanics for the game. I want to be able to select 1 block at a time.

If black is selected, I cannot select any other block. I have been working on this issue for 2 hours and still stuck.

Can someone give me advice on this issue?

Here is a snippet of code of where the problem lies

suspectDict = {Suspects(50, 85, 40, 60, "black", 5): "I am a black box",
               Suspects(100, 85, 40, 60, "blue", 5): "I am a blue box",
               Suspects(150, 85, 40, 60, "white", 5): "I am a white box"}

        if event.type == pygame.MOUSEBUTTONDOWN:
            mouse = pygame.mouse.get_pos()
            # print(mouse)
            # if mouse clicks area of the box (key) display value and change border
            for sprite,value in suspectDict.items():
                if sprite.set_rect.collidepoint(event.pos):
                    if sprite.border == 0:
                        sprite.border = 5


                    else:
                        sprite.border = 0
                        print(value)

    # RENDER GAME HERE
    for i in suspectDict:
        i.drawSquare(screen)

I have attached a video of the issue

https://imgur.com/a/RPtM0iR

Posted Mar 1, 2026, 1:40 AM UTC

714
Loading comments…