0

I'm using Pygame to display animated full screen images on my second monitor. However, as soon as I click any window on the first monitor, the Pygame window closes. How can I prevent that?

Note that this happens only on my linux machine, on Mac OS the windows stays open.

Here's some reduced code:

import pygame
import pygame.locals

pygame.init()
windowSurface = pygame.display.set_mode((1280, 1080), pygame.locals.FULLSCREEN)

img = pygame.image.load("someimage.png")

running = True
while running:
    windowSurface.blit(img, (0, 0))
    pygame.display.flip()

    for event in pygame.event.get():
        if (event.type == pygame.locals.QUIT or
            (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)):
            print("QUIT!")
            running = False
pygame.quit()

Note that opening the window initially is not the problem, the image loads just fine.

Boris Lau
  • 55
  • 1
  • 9
  • What path does the code take? Are there any exceptions that terminate the program? – Ulrich Eckhardt Jul 11 '22 at 15:14
  • Defocusing the window closes the window, but the code keeps running as if nothing happened. – Boris Lau Jul 11 '22 at 15:28
  • This is likely a problem with the fiel path. See [Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."](https://stackoverflow.com/questions/58177145/could-not-open-resource-file-pygame-error-filenotfounderror-no-such-file-or) – Rabbid76 Nov 22 '22 at 15:24
  • I don't think so, in that case the window would not show the image at all, but that's not the problem here. It rather seems to be a "feature" of the window manager I'm using (XFCE). – Boris Lau Nov 28 '22 at 08:38

0 Answers0