The Text Widget: What Is It and Why Use It?
The text widget is an incredibly versatile tool that lets you insert formatted text in your Python Playground applications. The cool part? It uses markdown syntax, so if you’re already familiar with this markup language (who isn’t these days?), you’re halfway there!
Getting started is super easy:
from story import create
story = create()
text_widget = story.text()
text_widget.write("My first text")
The Magic of Markdown in the Text Widget
Give Your Text Some Style
Want to make your text more interesting? Here’s how:
text_widget.write("""
# My Awesome Title
This text has some *italic* words
and some in **bold**.
And check this out: ***bold italic***!
""")
Lists? Piece of Cake!
Organizing information has never been easier:
text_widget.write("""
* Coffee
* Keyboard
* Mouse
* Monitor
* Creativity
1. Write code
2. Debug
1. Breathe
2. Try again
""")
Code? Markdown’s Got You Covered
Make your code snippets shine:
text_widget.write("""
Here's some code: `print("Hello!")`
And here's a complete block:
`python
def greet(name):
return f"Hello {name}!"
`
""")
A Practical Example: Your First Presentation
Let’s put together everything we’ve learned into a real presentation:
from story import create
story = create()
# Initial slide - let's make an impression!
text1 = story.text()
text1.write("""
# 🚀 My Python Project
* Innovative
* Fast
* Open Source
""")
# Build some suspense...
story.sleep(2)
# Now for the technical details
text2 = story.text()
text2.write("""
## How Does It Work?
Here's an example:
`python
def magic():
return "✨ Done! ✨"
`
""")
# Launch the presentation!
await story.run()
Tips and Tricks
- Keep the Rhythm: Use
story.sleep()
strategically to give the right reading time - One Widget per Slide: Create a new text widget for each logical section
- Consistent Formatting: Choose a style and stick to it throughout your presentation
- Test, Test, Test: Always check how the final result looks
What’s Next?
The text widget is a powerful tool that lets you create dynamic and interactive presentations in Python Playground. With markdown syntax, you can transform your ordinary text into something extraordinary.