Getting Started with Python Playground
First, we need to import and initialize our story:
from story import create
# Create a new story
story = create()
Basic Text Widget Usage
Here are some practical examples of how to use the Text widget:
Example 1: Simple Text
from story import create
# Create a new story
story = create()
# Create a new text widget
text = story.text()
text.write("# Welcome to the Math Lesson!")
# Run the story
await story.run()
Example 2: Simple Mathematical Formula
from story import create
story = create()
text = story.text()
text.write("""
# The Quadratic Formula
The solution to a quadratic equation $ax^2 + bx + c = 0$ is:
$$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$
""")
await story.run()
Example 3: Step-by-Step Sequence with Timing
from story import create
story = create()
# First step
text1 = story.text()
text1.write("Let's start with a simple equation: $2x + 3 = 11$")
# Add a pause
story.sleep(1)
# Second step
text2 = story.text()
text2.write("Subtract 3 from both sides: $2x = 8$")
# Another pause
story.sleep(1)
# Final result
text3 = story.text()
text3.write("Therefore: $x = 4$")
await story.run()
Example 4: Combining Text and Whiteboard
from story import create
story = create()
# Text explanation
text = story.text()
text.write("""
# Rectangle Area
The area of a rectangle is given by the formula:
$$A = base \\times height$$
""")
# Graphical visualization
wb = story.whiteboard(400, 300)
wb.draw(50, 50, 200, 100, "blue")
wb.text(100, 200, "Area = 200 × 100 = 20000", "black", "20px Arial")
await story.run()
Example 5: Advanced Mathematical Presentation
from story import create
story = create()
text = story.text()
text.write("""
# Integration by Parts
The formula for integration by parts is:
$$\\int u\\,dv = uv - \\int v\\,du$$
Practical example with $\\int x\\cos(x)\\,dx$:
1. Let's choose:
* $u = x$
* $dv = \\cos(x)\\,dx$
2. Therefore:
* $du = dx$
* $v = \\sin(x)$
3. Applying the formula:
$$\\int x\\cos(x)\\,dx = x\\sin(x) - \\int \\sin(x)\\,dx$$
""")
await story.run()
Best Practices
Code Structure
- Always initialize a new story with
create()
- Use
story.sleep()
to control timing - Always close with
await story.run()
- Always initialize a new story with
Text Formatting
- Use Markdown for basic formatting
- Insert inline formulas with
$...$
- Use
$$...$$
for display formulas
Performance
- Avoid creating too many consecutive text widgets
- Use strategic pauses with
sleep()
to improve readability - Combine multiple content pieces in a single text widget when possible
Advanced Tips
- Step-by-Step Animations
from story import create
story = create()
# Introduction
text1 = story.text()
text1.write("# Let's solve step by step")
story.sleep(1)
# Initial equation
text2 = story.text()
text2.write("$3x + 5 = 20$")
story.sleep(1)
# First step
text3 = story.text()
text3.write("$3x = 15$")
story.sleep(1)
# Solution
text4 = story.text()
text4.write("$x = 5$")
await story.run()
- Complex Mathematical Explanations
from story import create
story = create()
text = story.text()
text.write("""
# The Derivative of a Product
The product rule states that:
$$\\frac{d}{dx}[f(x)g(x)] = f(x)\\frac{d}{dx}[g(x)] + g(x)\\frac{d}{dx}[f(x)]$$
Let's apply this to $f(x) = x^2$ and $g(x) = \\sin(x)$:
$$\\frac{d}{dx}[x^2\\sin(x)] = x^2\\cos(x) + 2x\\sin(x)$$
""")
await story.run()
Tips for Educational Content
Structure Your Lessons
- Start with a clear title and objectives
- Break down complex concepts into smaller steps
- Use appropriate pauses between concepts
Enhance Understanding
- Combine textual explanations with visual elements
- Use color-coding for important elements
- Include practical examples
Interactive Elements
- Use the whiteboard for visual demonstrations
- Create step-by-step revelations
- Include practice problems and solutions
Conclusion
The Text widget in Python Playground offers a flexible and powerful way to create interactive mathematical content. By combining text, mathematical formulas, and appropriate timing, you can create clear and effective mathematical presentations.