1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] how to wrap a function inside a function in a single line to pass an arguments...

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    assume i have a simple funtion with 1 parameter

    def handle_click(text):
    print(text)


    and i have many buttons and each of them has to pass different text to handle_click function

    if i will pass an argument inside the button it will automatically all the funtion like:

    Button(command=handle_click("display this"))
    Button(command=handle_click("display that"))
    Button(command=handle_click("show this"))
    Button(command=handle_click("show that"))


    but i want this function to be triggred when the button is clicked

    In React.js i could use arrow funtion and do it like:

    <Button onClick={() => {handleClick("show this")} }>
    <Button onClick={() => {handleClick("show that")} }>
    <Button onClick={() => {handleClick("so on")} }>
    <Button onClick={() => {handleClick("so forth")} }>

    Continue reading...

Compartilhe esta Página