Python >> Tutoriel Python >  >> Python GUI >> Pygame GUI

Comment puis-je obtenir la taille (largeur x hauteur) de ma fenêtre pygame

Vous voulez obtenir la surface, puis obtenir la taille de l'objet de surface.

Utilisation du déballage de tuple :

w, h = pygame.display.get_surface().get_size()


Vous pouvez obtenir la taille des fenêtres en obtenant d'abord la surface d'affichage. pygame.display.get_surface(), puis en appelant get_width() / get_height() sur la surface.


Comme ça !

surface = pygame.display.get_surface() #get the surface of the current active display
x,y = size = surface.get_width(), surface.get_height()#create an array of surface.width and surface.height