PYGLET - Accessing Label Text

PYGLET - Accessing Label Text

In pyglet, the Label class is used to display text. If you've created a Label object and want to access or modify its text later on, you can do so using the text attribute of the Label object.

Here's a basic example demonstrating how to access the text of a Label in pyglet:

import pyglet # Create a window window = pyglet.window.Window() # Create a label 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') @window.event def on_draw(): window.clear() label.draw() # Access the text of the label print(label.text) # Outputs: Hello, World! # Modify the text of the label label.text = 'Hello, pyglet!' print(label.text) # Outputs: Hello, pyglet! pyglet.app.run() 

In the above example, the label is created with the text 'Hello, World!'. We then access this text and print it. Later, we modify the text of the label to 'Hello, pyglet!' and print it again.


More Tags

splunk-query payara radio-group dart-2 sql-query-store gps powerapps android-optionsmenu latitude-longitude updates

More Programming Guides

Other Guides

More Programming Examples