pydraw
  • Home
  • Documentation
  • Guides
    • Installation and Setup
    • Getting Started
    • Quickstart Examples
  • Quick Reference
    • Screen
    • Color
    • Location
    • Renderable
    • Text
    • Line
    • Image
    • Input
    • Scene
Powered by GitBook
On this page
  • Initialization
  • Text
  • Dimensions
  • Font
  • Size
  • Align
  • Decorations

Was this helpful?

  1. Quick Reference

Text

A brief reference to the Text class.

PreviousRenderableNextLine

Last updated 2 years ago

Was this helpful?

Text extends the Renderable class but has some unique methods that are listed below.

Initialization

Text can be initialized like this:

text = Text(screen, text, x, y)

There an extended constructor that contains most attributes, check the full documentation:

Text

You can get or change the text displayed with:

text.text()  # Get the current text
text.text('new string!')  # Set new text

Dimensions

pyDraw will automatically calculate a width and height once you've created a Text object (or when you update it's attributes), so you can get those values like so:

text.width()
text.height()

Font

You can access the font of the text with:

text.font()  # The current font
text.font(font)  # Set a new font

Size

You can also modify the font-size as expected:

text.size()  # Retrieve the current font-size
text.size(16)  # Set a new font-size (~height in pixels)

The width() and height() methods will only return the height of the text created as they are determined by text, font, and font-size, and cannot be set.

Align

You can specify an alignment for cases where multiple lines of text are given:

Possible Values (string):

  • left

  • center

  • right

text.align(alignment)

Decorations

You can decorate text with the following methods:

text.bold(True)
text.italic(True)
text.underline(True)
text.strikethrough(True)

Renderable Quick Reference
Text Documentation
Text