Web Analytics Made Easy - Statcounter
Skip to content

Text

Text call reference

Displays text. Known as a "Label" widget in many GUI frameworks.

layout = [[sg.Text("Text!", font=("Calibri", 24))]]

text

Events

The Text element can generate an event if clicked with the mouse if enable_events is set to True. This can come in handy when using a Text element to:

  • Display a link that a user can click
  • Simulate a button

Values Dictionary

The Text element does not have a Values Dictionary entry.

Size

If no size is provided, then the Text element will grow and shrink to fit the current value of the text. Most fonts are not mono-spaced fonts so be aware that the pixel width for a string of 10 characters will vary depending on which 10 characters you use.

These 2 strings:

'..........'
'WWWWWWWWWW'

are clearly different sizes when proportional spaced fonts are used. Mono-spaced fonts, like Courier New, mean each character will the same size regardless of the character. Here are those same 2 strings using a mono-spaced font: '..........'
'WWWWWWWWWW'

They're the same width using a mono-spaced font.

Justification

The justification parameter can be confusing. It signifies how your string will be justified within the Text element itself. A string that's 20 characters in length will appear the same regardless of the justification parameter if the Text element is 20 characters wide.

To see actual justification happening you'll need either to make the size of the element larger than the string or set expand_x to True so that the element will expand to take all available space horizontally.