How to pass a value for a flet button event[Question] #2617
-
QuestionHow to pass a value for a flet button event: Code sample#This is the code
import flet as ft
class ImageView:
def __init__(self, view, list):
for ctnet in list:
image =ft.Container(
#I want to pass the value of ctnet to the ImageInfor() function via this click event
on_click=self.ImageInfor(e, i=ctnet),
padding=10,
content=ft.Column(
controls=[
ft.Image(
width=600,
height=350,
src=ctnet,
fit=ft.ImageFit.FILL,
repeat=ft.ImageRepeat.NO_REPEAT,
border_radius=ft.border_radius.all(15),
),
ft.Row(
controls=[
ft.Text(
"title",
style=ft.TextStyle(
size=20,
),
)
]
)
]
)
)
view.controls.append(image)
def ImageInfor(e,i): #Receive the click event and its value here
def infor():
print("clicked:", i)
return infor Error messageBut I can't pass the value, it shows: #on_click=self.ImageInfor(i=ctnet),
TypeError: ImageView.ImageInfor.<locals>.infor() takes 0 positional arguments but 1 was given
But when I pass in e, it shows: #on_click=self.ImageInfor(e, i=ctnet),
NameError: name 'e' is not defined
When I remove the e in the receive function, it shows:
TypeError: ImageView.ImageInfor() got multiple values for argument 'i'
I'm not sure if the flet can convey something similar to e: ft. FilePickerResultEvent ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Feb 13, 2024
Replies: 1 comment
-
In the callback definition at the bottom, leave just |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AthenaRoland
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the callback definition at the bottom, leave just
e
.At the
on_click
level, remove the calling brackets(...)
, leaving just the callback's name.