Todo.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import flet as ft
  2. from flet_core import Column, MainAxisAlignment
  3. class TodoPage(Column):
  4. def add_clicked(self, e):
  5. if self.new_task.value:
  6. self.list.controls.append(ft.Checkbox(label=self.new_task.value))
  7. self.new_task.value = ""
  8. self.new_task.focus()
  9. self.new_task.update()
  10. self.page.update()
  11. # self.page.update()
  12. else:
  13. self.page.dialog = self.dlg
  14. self.dlg.open = True
  15. self.page.update()
  16. def __init__(self):
  17. super().__init__()
  18. self.controls.clear()
  19. self.dlg = ft.AlertDialog(title=ft.Text("请输入内容!"), on_dismiss=lambda e: print("关闭提示!"))
  20. self.new_task = ft.TextField(hint_text="添加想要干的事情", width=300,on_submit=self.add_clicked)
  21. # self.add_btn = ft.IconButton(ft.icons.ADD, tooltip="添加", icon_color=ft.colors.BLACK87,
  22. self.add_btn = ft.FloatingActionButton(icon=ft.icons.ADD, bgcolor=ft.colors.LIME_300, on_click=self.add_clicked)
  23. # // ft.ElevatedButton("Add", on_click=self.add_clicked)
  24. self.list = ft.Column(alignment=ft.alignment.top_left)
  25. self.list.controls.append(ft.Checkbox(label='Java'))
  26. self.list.controls.append(ft.Checkbox(label='Python'))
  27. self.list.controls.append(ft.Checkbox(label='AI'))
  28. self.list.controls.append(ft.Checkbox(label='开源项目计划'))
  29. content = ft.Column([
  30. ft.Row(controls=[self.new_task, self.add_btn]),
  31. self.list
  32. ])
  33. self.controls.append(content)