Size and position

This section applies only to windows that are not fullscreen. Fullscreen windows always have the width and height of the screen they fill.

You can specify the size of a window as the first two arguments to the window constructor. In the following example, a window is created with a width of 800 pixels and a height of 600 pixels:

window = pyglet.window.Window(800, 600)

The "size" of a window refers to the drawable space within it, excluding any additional borders or title bar drawn by the operating system.

You can allow the user to resize your window by specifying resizable=True in the constructor. If you do this, you may also want to handle the on_resize event:

window = pyglet.window.Window(resizable=True)

@window.event
def on_resize(width, height):
    print 'The window was resized to %dx%d' % (width, height)

You can specify a minimum and maximum size that the window can be resized to by the user with the set_minimum_size and set_maximum_size methods:

window.set_minimum_size(320, 200)
window.set_maximum_size(1024, 768)

The window can also be resized programatically (even if the window is not user-resizable) with the set_size method:

window.set_size(800, 600)

The window will initially be positioned by the operating system. Typically, it will use its own algorithm to locate the window in a place that does not block other application windows, or cascades with them. You can manually adjust the position of the window using the get_position and set_position methods:

x, y = window.get_location()
window.set_location(x + 20, y + 20)

Note that unlike the usual coordinate system in pyglet, the window location is relative to the top-left corner of the desktop, as shown in the following diagram:

window_location.png

The position and size of the window relative to the desktop.