PYGLET – Creating window
Last Updated :
31 May, 2021
In this article we will see how we can create a window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc on Windows, Mac OS and Linux. This library is created purely in Python and it supports many features like windowing, user interface event handling, Joysticks, OpenGL graphics, loading images, and videos, and playing sounds and music. A window is a “heavyweight” object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). When floating, windows may appear borderless or decorated with a platform-specific frame (including, for example, the title bar, minimize and close buttons, resize handles, and so on).
In order to create window we use Window method with the pyglet.window
Syntax : pyglet.window.Window(width, height, title)
Argument : It takes optional arguments i.e width, height and title of window
Return : It returns pyglet.window.win32.Win32Window object
Note : Either we provide no argument or we have to prove all three arguments else error would generate
Example :
Python3
from pyglet import *
width = 400
height = 400
title = "PYGLET GfG"
win = window.Window(width, height, title)
app.run()
|
Output :
Another Example :
Python3
import pyglet
width = 500
height = 500
title = "Geeksforgeeks"
window = pyglet.window.Window(width, height, title)
label = pyglet.text.Label( 'GeeeksforGeeks' ,
font_name = 'Times New Roman' ,
font_size = 36 ,
x = window.width / / 2 , y = window.height / / 2 ,
anchor_x = 'center' , anchor_y = 'center' )
@window .event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...