Skip to content

Commit a93b193

Browse files
committed
Update calculator tutorial and example script
Added a main guard to calc2.py to allow direct execution. Updated calculator tutorial documentation to use new image paths, correct code references, and improve clarity.
1 parent e216973 commit a93b193

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

sdk/python/examples/tutorials/calculator/calc2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ def main(page: ft.Page):
4949
)
5050

5151

52-
ft.run(main)
52+
if __name__ == "__main__":
53+
ft.run(main)

sdk/python/packages/flet/docs/tutorials/calculator.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Calculator Tutorial
33
examples: ../../examples/tutorials/calculator
4+
example_images: ../test-images/tutorials/golden/macos/calculator
45
---
56

67
In this tutorial you will learn, step-by-step, how to create a Calculator app in
@@ -17,7 +18,6 @@ In this tutorial, we will cover all of the basic concepts for creating a Flet ap
1718
building a page layout, adding controls, making reusable UI components, handling
1819
events, and publishing options.
1920

20-
The tutorial consists of the following steps:
2121

2222
## Getting started with Flet
2323

@@ -62,7 +62,7 @@ Create `calc.py` with the following contents:
6262

6363
Run the app and you should see a page like this:
6464

65-
{{ image("../examples/tutorials/calculator/media/app-1.png", alt="app-1", width="80%") }}
65+
{{ image(example_images + "/calc1.png", alt="calc1", width="50%") }}
6666

6767

6868
## Building page layout
@@ -77,7 +77,7 @@ Replace `calc.py` contents with the following:
7777

7878
Run the app and you should see a page like this:
7979

80-
{{ image("../examples/tutorials/calculator/media/app-2.png", alt="app-2", width="80%") }}
80+
{{ image(example_images + "/calc2.png", alt="calc2", width="50%") }}
8181

8282

8383
### Using Container for decoration
@@ -162,7 +162,7 @@ We will be using these new classes now to create rows of buttons in the Containe
162162
content = ft.Column(
163163
controls=[
164164
ft.Row(
165-
controls=[self.result],
165+
controls=[result],
166166
alignment=ft.MainAxisAlignment.END,
167167
),
168168
ft.Row(
@@ -216,7 +216,7 @@ content = ft.Column(
216216
```
217217
///
218218

219-
{{ image("../examples/tutorials/calculator/media/app.png", alt="calc-app", width="80%") }}
219+
{{ image(example_images + "/calc3.png", alt="calc3", width="50%") }}
220220

221221

222222
Just what we wanted!
@@ -235,7 +235,7 @@ Flet apps with composability and reusability in mind.
235235
To make a reusable Calc app component, we are going to encapsulate its state and
236236
presentation logic in a separate `CalculatorApp` class.
237237

238-
Copy the entire code for this step from [here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/calc/calc4.py).
238+
Copy the entire code for this step from [here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/calculator/calc4.py).
239239

240240
/// admonition | Try something
241241
type: example
@@ -271,7 +271,7 @@ def button_clicked(self, e):
271271
With similar approach, `button_click` method will handle different calculator actions
272272
depending on `content` property for each button.
273273
Copy the entire code for this step from
274-
[here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/calc/calc.py).
274+
[here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/calculator/calc.py).
275275

276276
Run the app and see it in the action:
277277
{{ image("../examples/tutorials/calculator/media/app.gif", alt="calc-app2", width="80%") }}

0 commit comments

Comments
 (0)