user14074797
user14074797

Reputation:

Pygame switching from fullscreen to normal does not work

im currently trying to have a setting to switch from windowed mode and fullscreen. But after getting into fullscreen and trying to go back, the game bugs really weird and sticks to the topleft corner

Btw: display_width = 1280 display_height = 720

    elif (Settings_Menu == True):
        screen.fill((0,0,0))
        screen.blit(settingsscreen, (0,0))
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    if checkbox1.collidepoint(event.pos):
                        if(Fullscreen == False):
                            Fullscreen = True
                            screen = pygame.display.set_mode((display_width, display_height), pygame.FULLSCREEN)
                        else:
                            Fullscreen = False
                            screen = pygame.display.set_mode((display_width, display_height), pygame.RESIZABLE)

Upvotes: 2

Views: 431

Answers (3)

AnGlonchas
AnGlonchas

Reputation: 1

i had this problem and fixed it with:

pygame.display.set_mode(size,pygame.SCALED)

and then i wrote pygame.display.toggle_fullscreen() and worked.

Upvotes: 0

Rabbid76
Rabbid76

Reputation: 210878

Use pygame.display.toggle_fullscreen() to switch between fullscreen and windowed displays.

for event in pygame.event.get():
    if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
            if checkbox1.collidepoint(event.pos):
                pygame.display.toggle_fullscreen()

The documentation documentation mentions that display driver support "is not great" when using Pygame 1, but it should work for the following display drivers in Pygame 2:

  • windows (Windows)
  • x11 (Linux/Unix)
  • wayland (Linux/Unix)
  • cocoa (OSX/Mac)

However, at the time of writing this answer, there is a bug in toggle_fullscreen for Windows:

display.toggle_fullscreen does not work when toggling a maximized window to fullscreen #2380

Upvotes: 2

Starbuck5
Starbuck5

Reputation: 1874

This is a known bug in pygame 2.0 and 2.0.1. Reported on github here

The author there also found a workaround where you quit pygame between switching fullscreen.

Unfortunately, the toggle_fullscreen documentation is wrong. It does not work on windows. Reported on github

Now you might think- pygame has way too many problems with fullscreen, which is reasonable. But they are being fixed. I submitted a patch for your issue which was merged a week ago and will be included in pygame 2.0.2.

Upvotes: 2

Related Questions