PYGLET – Obtener visualización de la ventana

En este artículo veremos cómo podemos obtener la visualización de la ventana en el módulo PYGLET en python. Pyglet es una biblioteca fácil de usar pero poderosa para desarrollar aplicaciones GUI visualmente ricas como juegos, multimedia, etc. Una ventana es un objeto «pesado» que ocupa los recursos del sistema operativo. Las ventanas pueden aparecer como regiones flotantes o pueden configurarse para llenar una pantalla completa (pantalla completa). La visualización de la ventana es la visualización a la que pertenece esta ventana. Es un archivo de solo lectura. Podemos crear una ventana con la ayuda del comando que se indica a continuación.

 pyglet.window.Window(width, height, title)

Para crear una ventana, usamos el atributo de visualización con el objeto de la ventana. 

Sintaxis: ventana.display 

Argumento: no requiere argumento 

Retorno: Devuelve el objeto Win32Display

A continuación se muestra la implementación. 

Python3

# importing pyglet module
import pyglet
import pyglet.window.key
 
# width of window
width = 500
 
# height of window
height = 500
 
# caption i.e title of the window
title = "Geeksforgeeks"
 
# creating a window
window = pyglet.window.Window(width, height, title)
 
# text
text = "GeeksforGeeks"
 
# creating a label with font = times roman
# font size = 36
# aligning it to the centre
label = pyglet.text.Label(text,
                          font_name ='Times New Roman',
                          font_size = 36,
                          x = window.width//2, y = window.height//2,
                          anchor_x ='center', anchor_y ='center')
 
new_label = pyglet.text.Label(text,
                          font_name ='Times New Roman',
                          font_size = 10,
                          x = 25, y = 25)
 
# on draw event
@window.event
def on_draw():   
 
     
    # clearing the window
    window.clear()
     
    # drawing the label on the window
    label.draw()
 
     
# key press event   
@window.event
def on_key_press(symbol, modifier):
 
    # key "C" get press
    if symbol == pyglet.window.key.C:
         
        # closing the window
        window.close()
     
 
# image for icon
img = image = pyglet.resource.image("logo.png")
 
# setting image as icon
window.set_icon(img)
 
# getting window display
value = window.display
 
# printing the value
print("Window Display : ")
print(value)
 
                
# start running the application
pyglet.app.run()

Producción :

 

Window Display: 
pyglet.canvas.win32.Win32Display object at 0x000001879C99DA08

Publicación traducida automáticamente

Artículo escrito por rakshitarora y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *