Mohammad Baygi
Mohammad Baygi

Reputation: 634

How switch full screen in a pygame surface window

How can I make my Pygame surface to be full screen? I have tried the following:

pygame.display.toggle_fullscreen()

but it does not do what I need.

Upvotes: 3

Views: 11385

Answers (3)

Mohammad Baygi
Mohammad Baygi

Reputation: 634

Thanks elegent for your answer. I finally found the answer from some othere post that was not even intended to answer my question:

import pygame
import ctypes

def set_screen_prop():
    user32 = ctypes.windll.user32
    screenSize =  user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
    print screenSize
    size = (screenSize)
    pygame.display.set_caption("Window")
    return pygame.display.set_mode((size) , pygame.FULLSCREEN)

pygame.init()
window=set_screen_prop()
pygame.quit()

Upvotes: 0

elegent
elegent

Reputation: 4007

I know it is not really a elegant, but you could call Pygames display.set_mode() function each time you want to change your screen mode (i.e. size, display flags).

You need to shut down the entire display module display.quit() first and initialize display.init() it again afterwards.

import pygame as pyg

pyg.init()
screen = pyg.display.set_mode((200, 300), pyg.RESIZABLE)

screen.fill((255,155,55))
pyg.display.flip()

while True:

    ev = pyg.event.wait()

    if ev.type == pyg.MOUSEBUTTONDOWN and ev.button == 1:
        # Display in Fullscreen mode
        pyg.display.quit()
        pyg.display.init()
        screen = pyg.display.set_mode((0, 0), pyg.FULLSCREEN)

    elif ev.type == pyg.MOUSEBUTTONDOWN and ev.button == 2:
        # Display in Resizable mode
        pyg.display.quit()
        pyg.display.init()
        screen = pyg.display.set_mode((200, 300), pyg.RESIZABLE)

    screen.fill((255,155,55))
    pyg.display.flip()

Upvotes: 2

oxrock
oxrock

Reputation: 641

Grabbed this from somewhere a while back, can't remember the source:

display = (1280,720) #whatever you want the screen size to be
if event.key == K_h: #Just a key to toggle fullscreen
    if pygame.display.get_driver()=='x11':
        pygame.display.toggle_fullscreen()
    else:
        acopy=screen.copy()                    
    if fullscreen:
        screen=pygame.display.set_mode(display)
    else:
        screen=pygame.display.set_mode(display, pygame.FULLSCREEN)
        fullscreen= not fullscreen
        screen.blit(acopy, (0,0))                    
        pygame.display.update()

Upvotes: 0

Related Questions