Replies: 1 comment
-
I think user event handlers are not implemented yet. import typing as t
import flet as ft
class MyControl(ft.UserControl):
def __init__(self, on_stuff: t.Callable[[str], None]) -> None:
super().__init__()
self._count = 0
self._on_stuff = on_stuff
def build(self) -> ft.Control:
return ft.TextButton("Fire on_stuff event", on_click=self._handle_stuff_event)
def _handle_stuff_event(self, e: ft.ControlEvent) -> None:
self._count += 1
self._on_stuff(f"Stuff has been fired {self._count} times!")
def main(page: ft.Page) -> None:
def do_stuff(message: str) -> None:
page.add(ft.Text(message))
page.add(MyControl(on_stuff=do_stuff))
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Question
I have a
UserControl
that combines a button to bring up a file picker and a text field to show the selected file name. When the selected file changes I want it to emit a custom 'changed' event, that other controls can listen to and update their content. Is there a way to utilize the same event mechanism as the built in controls for this? Thanks!If cobbled together the below by looking into the implementation of
FilePicker
, but I'm not really sure about the arguments for theFileSelectorFileChangedEvent
ctor.Aside: for some reason
FilePickerResultEvent
doesn't call it's base class__init__
and I suspect that means an event handler would not be able to access e.g.e.control
to get the control that sent the event?Code sample
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions