get_display()
With get_display(), you can get the default display device.
If a Display connection already exists, that display will be returned. A default Display is created and returned if none is specified. If there are multiple active display connections, an arbitrary one is returned.
class Display(name=None, x_screen=None)
A display device that can accommodate one or more screens.
get_default_screen()
Get the user's default screen based on their operating system preferences.
The return type is of Screen.
get_screens()
The get_screens() function helps to get the available screens.
One Display with multiple Screens is typical of a multi-monitor workstation. This method returns a list of screens that can be enumerated to determine which one should be displayed in full-screen mode.
The default screen will suffice for creating an OpenGL configuration.
The return type is list of Screen.
get_windows()
Using get_window() you can get the windows currently attached to this display.
The return type is sequence of Window.
name= None
It is the name of this display, if applicable. It is given in type str.
x_screen= None
The X11 screen number of this display, if applicable. It takes the type int.
class Screen(display, x, y, width, height)
Fullscreen windows are supported by this virtual monitor.
The majority of screens are mapped to a physical display such as a monitor, television, or projector. Unless the window is made fullscreen, in which case the window will fill only that virtual screen, selecting a screen for a window has no effect.
The current resolution of a screen is determined by its width and height attributes. The top-left corner of the screen's global location is determined by the x and y attributes. This is useful for determining whether screens are stacked on top of each other or next to each other.
To get an instance of this class, call get screens() or get default screen().
get_best_config(template=None)
Get the best GL configuration you can.
In the template, you can specify any required attributes. NoSuchConfigException will be thrown if no configuration matches the template.
get_closest_mode(width, height)
Find the screen mode that best fits a specific size.
A larger mode is returned if no supported mode exactly matches the requested size; or None if no mode is large enough.
get_matching_configs(template)
Get a list of configurations that match a set of criteria.
Each returned config will have values equal to or greater than any attributes specified in the template. An empty list is returned if no configs satisfy the template.
get_mode()
This screen's current display mode is returned.
get_modes()
Get a list of the screen modes that this screen supports.
restore_mode()
Reset the screen mode to the user's preferred setting.
set_mode(mode)
This screen's display mode can be changed.
The mode must have been returned previously by get_mode() or get_modes ().
display
This screen is part of a display.
height
The screen's height in pixels.
width
The screen's width in pixels.
x
On the virtual desktop, the left edge of the screen.
y
On the virtual desktop, the top edge of the screen.
class Canvas(display)
Area for abstract drawing.
Internally, pyglet uses canvases to represent drawing areas, which can be in a window or full-screen.
The display is the Display this canvas was created on.
FAQs
How do I close Pyglet on Windows?
A window is a "heavyweight" object that consumes resources from the operating system. Windows can be set to appear as floating regions or to fill the entire screen (fullscreen). Although we can manually close a window by pressing the close button, there are times when we need to close a window programmatically.
Which is better pygame or Unity?
Build high-quality 3D and 2D games with Unity, then distribute them across mobile, desktop, VR/AR, consoles, and the Web to connect with loyal and enthusiastic players and customers; pygame: An open-source python programming language library for creating multimedia applications.
Is pygame easy?
Python is frequently recommended as the best "first programming language" to learn because of its simple syntax and gradual learning curve. As a result, a lot of new programmers start with Python. Pygame is a Python extension that follows Python's philosophy and aims to be simple to use.
What is pyglet used for?
Python's pyglet library is a cross-platform windowing and multimedia library for creating games and other visually rich applications. Windowing, user interface event handling, game controllers and joysticks, OpenGL graphics, image and video loading, and sound and music playback are all supported.
Does pyglet work on Mac?
On Windows, Mac OS X, and Linux, pyglet is a powerful yet simple Python library for creating games and other visually rich applications. Windowing, user interface event handling, joysticks, OpenGL graphics, loading images and videos, and sound and music playback are all supported.
Conclusion
In this article, we saw the theoretical and practical implementation of pyglet.canvas in game development.
We hope that this blog has helped you enhance your knowledge regarding pyglet.canvas in game development. If you would like to learn more about Pyglet Library, Why is Pyglet used, Asteroids game using Pyglet, and more, check out our articles on Coding Ninjas Studio. Do upvote our blog to help other ninjas grow. Happy Coding!