How to pass arguments to a Button command in Tkinter?

Suppose I have the following Button made with Tkinter in Python:

import Tkinter as Tk
win = Tk.Toplevel()
frame = Tk.Frame(master=win).grid(row=1, column=1)
button = Tk.Button(master=frame, text="press", command=action)

The method action is called when I press the button, but what if I wanted to pass some arguments to the method action?

I have tried with the following code:

button = Tk.Button(master=frame, text="press", command=action(someNumber))

This just invokes the method immediately, and pressing the button does nothing.

18 Answers
18

Leave a Comment