pygame window not responding when clicked

Kamil

I'm using pygame for interface display and controller input on a project I'm working on. Currently everything works sufficiently well so this isn't a major concern, but if it accidentally happens during actual use there might be some problems so I'd like to fix it possible.

When I run my code, the pygame window appears, displays, and updates exactly as expected. However, if I click on it or it gains focus some other way the window freezes and becomes (Not Responding). The code itself continues running, including the thread that is responsible for updating the display, until I close the window so Python itself is still running fine, but the window stops working.

My code for the update loop is here, in all its really ugly glory:

    while(1):
        print "thread is fine"
        pygame.event.pump()

        if LOV_Flag == 1:
            videoColor = (255, 0, 0)
        else:
            videoColor = (0, 255, 0)

        # Refresh the screen and redraw components

        screen.fill((255, 255, 255))
        pulseLabel = pulseFont.render("Pulse: ", 1, (0, 0, 0))
        videoLabel = videoFont.render("Video: ", 1, (0, 0, 0))
        motorsLabel = labelFont.render("Motors", 1, (0, 0, 0))
        motorLabel = captionFont.render("L         R", 1, (0, 0, 0))
        armLabel = captionFont.render("Arm", 1, (0, 0, 0))
        gripperLabel = captionFont.render("Gripper", 1, (0, 0, 0))
        screen.blit(motorsLabel, (55, 50))
        screen.blit(motorLabel, (60, 75))
        screen.blit(pulseLabel, (300, 19))
        screen.blit(videoLabel, (300, 45))
        screen.blit(armLabel, (250, 75))
        screen.blit(gripperLabel, (235, 255))
        leftBar = (50, 200 - drive.getSpeed()[0], 25, drive.getSpeed()[0])
        rightBar = (100, 200 - drive.getSpeed()[1], 25, drive.getSpeed()[1])
        armBar = (250, 200 - (100 * arm.report()), 25, (100 * arm.report()))
        upperArmBar = (250, 200 - (100 * arm.reportUp()), 25, 2) # 100 is the value on the bar
        lowerArmBar = (250, 200 - (100 * arm.reportDown()), 25, 2) # 135 (65) is the value on the bar
        gripperBar = (212, 225, (100 * hand.report()), 25)
        leftGripperBar = (212 + (100 * hand.reportClosed()), 225, 2, 25)
        rightGripperBar = (212 + (100 * hand.reportOpen()), 225, 2, 25)
        pygame.draw.rect(screen, (255, 0, 0), leftBar, 0)
        pygame.draw.rect(screen, (255, 0, 0), rightBar, 0)
        pygame.draw.rect(screen, (255, 0, 0), armBar, 0)
        pygame.draw.rect(screen, (0, 0, 0), upperArmBar, 0)
        pygame.draw.rect(screen, (0, 0, 0), lowerArmBar, 0)
        pygame.draw.rect(screen, (255, 0, 0), gripperBar, 0)
        pygame.draw.rect(screen, (0, 0, 0), leftGripperBar, 0)
        pygame.draw.rect(screen, (0, 0, 0), rightGripperBar, 0)
        pygame.draw.circle(screen, pulseColor, [370, 32], 10)
        pygame.draw.circle(screen, videoColor, [370, 58], 10)
        pygame.display.update()

        time.sleep(0.1)
        if killFlag:
            return

An image for how the window looks, in case that helps you understand the code better.

Kamil

I moved this code to main instead of a thread, it works now. I did end up needing the pygame.event.pump() line, and I now use clock.tick() for rate control, but it's otherwise identical but moved. Apparently pygame just doesn't play well with threading.

Thanks for all the help though, the actual solution may have been discovered accidentally but having things to try kept me trying long enough to try the thing I didn't expect to work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Tkinker window not responding when clicked on the "Exit"

Pygame: window not responding

pygame window keeps not responding

Pygame is opening a not responding window

Pygame window not responding error when i try to run a code

Button not responding when clicked

Pygame window not responding when I try to exit the window in the middle of execution or when I spam click on the window

Pygame Python window stops responding

Javascript button not responding when clicked

Pygame not responding when Doing calculations

The pygame window stops responding after running

Pygame Window not Responding after few seconds

Pygame window does not responding in fullscreen mode

Why is pygame.QUIT being checked when the 'X' button can be clicked and the window would be closed?

Pygame Not Responding

pygame window stops responding as the number of frames per seconds decrease

TKinter Window "Not Responding" When Trying to Open File

The application interface stops responding when dragging a window

Pygame window freezes when it opens

How to make tkinter's window not show "not responding" when click at window

Discord.js [not responding when message is sent after a button was clicked]

Pygame not responding when trying to show texts on macOS Sierra

Pygame not responding to variable updates

Pygame script stops responding

Pygame display not responding

Pygame not responding to keys

Pygame 'not responding' during animations

PyQt: Window stops responding when listening to ip, port

Error in Spinner in a Popup Window, it Crashes when Clicked