text
Displays a value as a static text.
Note that to create a text
control when using the Markdown syntax, you don't need to specify the
control name in the text template:
<|Some content|text|>
<|Some content|>
Properties¶
Name | Type | Default | Description |
---|---|---|---|
(★) |
Any dynamic |
"" | The value displayed as text by this control. |
raw |
bool |
False | If set to True, the component renders as an HTML <span> element without any default style. |
mode |
str |
Define the way the text is processed:
|
|
format |
str |
The format to apply to the value. |
|
width |
Union[str,int] |
None | The width of the element. |
id |
str |
The identifier that is assigned to the rendered HTML component. |
|
properties |
dict[str, Any] |
Bound to a dictionary that contains additional properties for this element. |
|
class_name |
str dynamic |
The list of CSS class names that are associated with the generated HTML Element. |
|
hover_text |
str dynamic |
The information that is displayed when the user hovers over this element. |
(★)value
is the default property for this visual element.
Details¶
The format property uses a format string like the ones used by the string format() function of Python.
If the value is a date
or a datetime
, then format can be set to a date/time
formatting string.
Usage¶
Display values¶
The property value can be set to any text that will be rendered.
This value must be a
Formatted string literals
so that if it includes Python expressions (potentially as simple as a variable name), the resulting
text is displayed.
You can represent a variable value as a simple, static text:
Definition
<|Hello {name}!|text|>
<taipy:text>Hello {name}!</taipy:text>
import taipy.gui.builder as tgb
...
tgb.text("Hello {name}!")
Presuming that the Python variable name is set to the value "Taipy", here is how this control displays:
![](../text-simple-d.png)
![](../text-simple-l.png)
Formatted output¶
If your value is a floating point value, you can use the format property to indicate what the output format should be used.
If we have the following Python definition:
pi = 3.14159265358979
To display this floating point value with three decimal places, we can create the text control as follows:
Definition
<|{pi}|text|format=%.3f|>
<taipy:text format="%.3f">{pi}</taipy:text>
import taipy.gui.builder as tgb
...
tgb.text("{pi}", format="%.3f")
Here is the resulting display:
![](../text-format-d.png)
![](../text-format-l.png)
Markdown formatting¶
You can use the Markdown markup language to add formatting indications to the text you want to
render.
You must set the mode property to "markdown" or "md" to do that.
Note that the Markdown syntax mentions that if a line ends with two white space characters, a line break is issued.
Here is an example of that feature.
Consider the following variable definition:
1 2 3 4 5 6 7 8 9 |
|
You cannot see that line 7 ends with two white space characters.
Let's bind this variable to the value property of the control and set mode so that Markdown formatting is issued:
Definition
<|{markdown}|text|mode=markdown|>
<taipy:text mode="markdown">{markdown}</taipy:text>
import taipy.gui.builder as tgb
...
tgb.text("{markdown}", mode="markdown")
The control looks like this on the page:
![](../text-md-d.png)
![](../text-md-l.png)
Note that a line break was forced where we expected it.
Preformatted text¶
You may need to store text that is preformatted (where spaces and line skips are essential). This
is really useful dealing with source code, for example.
Set the mode property to "pre" to indicate such a situation. The content is displayed
in a fixed-width font.
Line skips and space characters are crucial for Python code to be correctly interpreted.
Say you have the following Python variable definition, showing some raw Python source code:
1 2 3 4 5 6 |
|
We can use this variable in our text control and set mode to "pre":
Definition
<|{code}|text|mode=pre|>
<taipy:text mode="pre">{code}</taipy:text>
import taipy.gui.builder as tgb
...
tgb.text("{code}", mode="pre")
This is how the control is displayed:
![](../text-pre-d.png)
![](../text-pre-l.png)
Styling¶
All the text controls are generated with the "taipy-text" CSS class. You can use this class name to select the text controls on your page and apply style.