Main window and its stuff

PyGame's display module manage main window of your app. Basically it can set modes of display, check hardware info of current environment, set gamma, caption.

In PyGame coordinates strats from (0,0) in top left corner to (x,y) in bottom right corner. X is screen wight and y is screen height.


To initialize display use pygame.display.init(). You can call it multiple times with no harmful effect. Whats more pygame.init() call this routine internally for you.


pygame.display.quit() shuts down display module and also is called by pygame.quit()


To check if display is initialized use pygame.display.get_quit()


PyGame can render graphic in different modes such as:
pygame.FULLSCREEN a fullscreen display
pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL
pygame.HWSURFACE hardware accelerated, only in FULLSCREEN
pygame.OPENGL an opengl renderable display
pygame.RESIZABLE display window should be sizeable
pygame.NOFRAME display window will have no border or controls
To set one of them use pygame.display.set_mode(resolution=(0,0), flags=0, depth=0). Resolution is simple, but must say that in fullscreen PyGame if resolution is not present will try the closest one. flags are modes described below. It is recommended to not pass depth parameter because PyGame will find the bast and fast depth. If your game need special depth not available on some platform PyGame will emulate it.
This function as a result will return Surface object. We will talk about it more in next chapter.


Another way to get current surface is pygame.display.get_surface() that will return reference to it.


If just wont to know if particular mode is ok, test it with pygame.display.mode_ok(resolution, flags, depth).
To receive list of available modes use pygame.display.list_modes()


When use pygame.HWSURFACE calling pygame.display.flip() will print out graphic on screen. When using normal software surfaces better is pygame.display.update(rectangle=None) or pygame.display.update(rectanglelist). They will update only given areas which can be good optimization.


Can you those fancy icons in top left corner of window ? You can have the same. To set an icon first load image to Surface then use pygame.display.set_icon(Surface)


To set caption use pygame.display.set_caption(title, iconyfied_title=None) where title is title and iconyfied_title is title show on iconyfied (minimalised) windows.


To recive current title use pygame.display.get_caption() that will return two variables title and iconyfied_title.


pygame.display.gl_set_attribute() and gl_get_attribute will set and get pygame.OPENGL


Pygame can use different drivers as display back ends. pygame.display.get_driver() returns name of current one.


pygame.display.Info() creates object with some data about hardware:
hw: True if the display is hardware accelerated
wm: True if windowed display modes can be used
video_mem: The megabytes of video memory on the display. This is 0 if unknown
bitsize: Number of bits used to store each pixel
bytesize: Number of bytes used to store each pixel
masks: Four values used to pack RGBA values into pixels
shifts: Four values used to pack RGBA values into pixels
losses: Four values used to pack RGBA values into pixels
blit_hw: True if hardware Surface blitting is accelerated
blit_hw_CC: True if hardware Surface colorkey blitting is accelerated
blit_hw_A: True if hardware Surface pixel alpha blitting is accelerated
blit_sw: True if software Surface blitting is accelerated
blit_sw_CC: True if software Surface colorkey blitting is accelerated
blit_sw_A: True if software Surface pixel alpha blitting is acclerated
current_h, current_h: Width and height of the current video mode, or of the
desktop mode if called before the display.set_mode is called.
(current_h, current_w are available since SDL 1.2.10, and pygame 1.8.0)
They are -1 on error, or if an old SDL is being used.


To obtain some information from OS use pygame.display.get_wm_info() which will return dictionary with diffrent data specific for those OS's. Mostly "window" will be present and will contain window id of current display.