You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated the ToDo tutorial to reference example code files using --8<-- includes instead of embedding code directly. Improved formatting, clarified instructions, and streamlined explanations for better readability and maintainability.
In this tutorial we will show you, step-by-step, how to create a To-Do app in Python using Flet framework and then publish it as a desktop, mobile or web app. The app is a single-file console program of just
@@ -22,55 +23,37 @@ The tutorial consists of the following steps:
22
23
*[Final touches](#final-touches)
23
24
*[Publishing the app](#publishing-the-app)
24
25
25
-
/// details | For beginners
26
-
type: info
27
-
To create a multi-platform app in Python with Flet, you don't need to know HTML, CSS or JavaScript, but you do need a basic knowledge of Python and object-oriented programming.
26
+
## Getting started with Flet
27
+
28
+
To create a multi-platform app in Python with Flet, you don't need to know HTML,
29
+
CSS or JavaScript, but you do need a basic knowledge of Python and object-oriented
30
+
programming.
28
31
29
32
Before you can create your first Flet app, you need to
30
-
[setup your development environment](../getting-started/installation.md).
33
+
[setup your development environment](../getting-started/installation.md), which requires Python 3.10 or above and `flet` package.
31
34
32
35
Once you have Flet installed, let's [create](../getting-started/create-flet-app.md) a simple hello-world app.
33
36
34
37
Create `hello.py` with the following contents:
35
38
36
39
```python title="hello.py"
37
-
import flet as ft
38
-
39
-
defmain(page: ft.Page):
40
-
page.add(ft.Text(value="Hello, world!"))
41
-
42
-
ft.run(main)
40
+
--8<--"{{ examples }}/hello.py"
43
41
```
44
42
45
-
Run this app, and you will see a new window with a greeting:
43
+
Run this app and you will see a new window with a greeting:
@@ -80,8 +63,7 @@ Run the app and you should see a page like this:
80
63
81
64
### Page layout
82
65
83
-
Now let's make the app look nice! We want the entire app to be at the top center of the page,
84
-
taking up 600 px width. The TextField and the "+" button should be aligned horizontally, and take up full app width:
66
+
Now let's make the app look nice! We want the entire app to be at the top center of the page, taking up 600 px width. The TextField and the "+" button should be aligned horizontally, and take up full app width:
@@ -128,54 +84,12 @@ Run the app and you should see a page like this:
128
84
129
85
### Reusable UI components
130
86
131
-
While we could continue writing our app in the `main` function, the best practice would be to
132
-
create a [reusable UI component](../cookbook/custom-controls.md). Imagine you are working on an app header, a side menu,
133
-
or UI that will be a part of a larger project. Even if you can't think of such uses right now,
134
-
we still recommend creating all your Flet apps with composability and reusability in mind.
87
+
While we could continue writing our app in the `main` function, the best practice would be to create a [reusable UI component](../cookbook/custom-controls.md). Imagine you are working on an app header, a side menu, or UI that will be a part of a larger project. Even if you can't think of such uses right now, we still recommend creating all your Flet apps with composability and reusability in mind.
135
88
136
-
To make a reusable To-Do app component, we are going to encapsulate its state and presentation
137
-
logic in a separate class:
89
+
To make a reusable To-Do app component, we are going to encapsulate its state and presentation logic in a separate class:
138
90
139
91
```python title="todo.py"
140
-
import flet as ft
141
-
142
-
classTodoApp(ft.Column):
143
-
# application's root control is a Column containing all other controls
144
-
def__init__(self):
145
-
super().__init__()
146
-
self.new_task = ft.TextField(hint_text="What needs to be done?", expand=True)
Each task item is represented by two rows: `display_view` row with Checkbox, "Edit" and "Delete"
205
-
buttons and `edit_view` row with TextField and "Save" button. `view` column serves as a container
206
-
for both `display_view` and `edit_view` rows.
117
+
Each task item is represented by two rows: `display_view` row with Checkbox, "Edit" and "Delete" buttons and `edit_view` row with TextField and "Save" button. `view` column serves as a container for both `display_view` and `edit_view` rows.
207
118
208
-
Before this step, the code was short enough to be fully included in the tutorial. Going forward,
209
-
we will be highlighting only the changes introduced in a step.
119
+
To encapsulate task item views and actions, we introduced a new `Task` class.
210
120
211
-
Copy the entire code for this step from [here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/todo/to-do-4.py). Below we will explain the changes we've done
212
-
to implement view, edit, and delete tasks.
121
+
Additionally, we changed `TodoApp` class to create and hold `Task` instances when the "Add" button is clicked.
213
122
214
-
To encapsulate task item views and actions, we introduced a new `Task` class:
123
+
For "Delete" task operation, we implemented `task_delete()` method in `TodoApp` class which accepts task control instance as a parameter.
0 commit comments