[Question] how to use Animation end callback? #3307
-
QuestionI want to repeat the animation action of moving the text inside a container from the rightmost side of the container to the left side of the container. Event's object data field contains the name of animation: opacity For example: c = ft.Container( Code sampleself.notice_text = ft.Text(value = "hello, this is for animate testing!!! hello",
text_align = "center",
size = self.height_value*0.08,
weight=ft.FontWeight.W_500,
color = ft.colors.WHITE,)
ft.Row(
controls = [
notice_text_container :=ft.Container(
offset=ft.transform.Offset(0.75, 0),
animate_offset=ft.animation.Animation(duration=18000),
on_animation_end = lambda e: animate_repeat(self, e.data),
content = self.notice_text
)
def animate_repeat(self, e):
time.sleep(0.5)
if e=="offset":
notice_text_container.offset = ft.transform.Offset(0.75, 0)
notice_text_container.animate_offset = ft.animation.Animation(15000)
notice_move_thread_2 = threading.Thread(target=animate_container, args=(self,))
notice_move_thread_2.daemon = True
notice_move_thread_2.start()
def animate_container(self):
time.sleep(0.5)
notice_text_container.offset = ft.transform.Offset(-1, 0)
self.update()
notice_move_thread = threading.Thread(target=animate_container, args=(self,))
notice_move_thread.daemon = True
notice_move_thread.start() Error messageAnimation actions do not repeat ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If you want someone to try your code and eventually help, then please share a runnable code repro. |
Beta Was this translation helpful? Give feedback.
-
I found a solution. There was a part where I was mistaken, but I resolved it. I modified the "def animate_repeat(self, e):" function part. Modified portion of the "def animate repeat(self, e)" function |
Beta Was this translation helpful? Give feedback.
I found a solution. There was a part where I was mistaken, but I resolved it.
I modified the "def animate_repeat(self, e):" function part.
And then, I created another function and placed inside it a code that calls the function “def animate_container(self)” using “thread”.
Modified portion of the "def animate repeat(self, e)" function
->
def animate_repeat(self, e):
print(e)
time.sleep(0.5)
if e=="offset":
notice_text_container.animate_offset.duration=0
notice_text_container.offset = ft.transform.Offset(0.6, 0)
self.update()