📅  最后修改于: 2023-12-03 14:45:44.257000             🧑  作者: Mango
In PYGLET, a Label object is a graphical object that displays text. It is commonly used in GUI programming for displaying text on windows, buttons, and other UI elements. In this tutorial, we will learn how to access the font name property of a Label object.
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello World',
font_name='Times New Roman',
font_size=36,
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
print(label.font_name)
This will output the font name 'Times New Roman'.
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello World',
font_name='Times New Roman',
font_size=36,
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
print(label.font_name)
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
In this tutorial, we have learned how to access the font name property of a Label object in PYGLET. By setting the font name property, we can easily change the font type of the displayed text.