How to pass arguments to a Button command in Tkinter ?

How to pass arguments to a Button command in Tkinter?

Asked on November 20, 2018 in tkinter.
Add Comment


  • 1 Answer(s)

    I personally prefer to use lambdas in such a scenario, because imo it’s clearer and simpler and also doesn’t force you to write lots of wrapper methods if you don’t have control over the called method, but that’s certainly a matter of taste.

    That’s how you’d do it with a lambda (note there’s also some implementation of currying in the functional module, so you can use that too):

    button = Tk.Button(master=frame, text='press', command= lambda: action(someNumber))
    
    Answered on February 9, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.