PYGLET - Accessing Formatted Document Text

PYGLET - Accessing Formatted Document Text

In Pyglet, the pyglet.text module provides utilities to create and manage text objects for rendering. Among them, the pyglet.text.document provides a way to handle formatted and unformatted documents.

The FormattedDocument class allows you to create a document with formatted text. Once you have a FormattedDocument, you can access its text content using the text attribute.

Here's a simple example demonstrating how to create a FormattedDocument and then access its text:

import pyglet from pyglet.text import FormattedDocument # Create a formatted document document = FormattedDocument("Hello, Pyglet!") # Access the text print(document.text) # Outputs: Hello, Pyglet! # You can also set the text: document.text = "New content for the document" print(document.text) # Outputs: New content for the document pyglet.app.run() 

This script will initialize a FormattedDocument with the string "Hello, Pyglet!" and then simply print it. It then modifies the document's text and prints the new content.


More Tags

noise animated-webp roguelike nonetype readfile font-awesome android-framelayout fixed-header-tables swiftmessages viewpropertyanimator

More Programming Guides

Other Guides

More Programming Examples