Skip to content

Need info about bind function. (multi arguments) #2188

Closed Answered by PierreQuentel
BobSquarePants asked this question in Q&A
Discussion options

You must be logged in to vote

Hi !

This kind of issue (which is not specific to Brython) is solved by passing the loop variable to the lambda function:

from browser import document

def f(ev, what):
    print(what)
    
for each in document.select('div'):
    each.bind("click", lambda ev, each=each: f(ev, what=each.name))

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@BobSquarePants
Comment options

Answer selected by BobSquarePants
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants