This can be done using a lambda, like so:

button = Tk.Button(master=frame, text='press', command= lambda: action(someNumber))

This is a simple way to bind the argument without an explicit wrapper method or modifying the original action.

Answer from Voo on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-pass-arguments-to-tkinter-button-command
How to Pass Arguments to Tkinter Button Command? - GeeksforGeeks
July 23, 2025 - # importing tkinter import tkinter as tk # defining function def func(args): print(args) # create root window root = tk.Tk() # root window title and dimension root.title("Welcome to GeekForGeeks") root.geometry("380x400") # creating button btn = tk.Button(root, text="Press", command=lambda: func("See this worked!")) btn.pack() # running the main loop root.mainloop()
Discussions

How to use a Tkinter button (call a function) that has an argument?
You can do this with lambda or partial. But not in this case, because you've misdignosed the problem. You need to make the entry an instance variable, then you will be able to access it from the method without passing it. class newTopLevel(object): def __init__(self, root): self.newWindow = Toplevel(root) self.entry_1 = tk.Entry(self.newWindow) # <==change here self.entry_1.grid(row=0, column=1) self.newWindow.btn = tk.Button(self.newWindow,text='Enter',command=self.fun) self.newWindow.btn.grid(row=0,column=2) def fun(self): get_value=self.entry_1.get() More on reddit.com
🌐 r/learnpython
11
1
November 20, 2020
How to call same function with different argument given from list in tkinter button command option
from tkinter import * def fun(nm): msg= 'hello {}'.format(nm) print(msg) master=Tk(className="testing") list=[1,2,3,4] for x in list: para=x Button(master, text=x, command=lambda:fun(x)).pack(side='left') master.mainloop() getting output hello 4 every time More on discuss.python.org
🌐 discuss.python.org
0
0
November 8, 2019
Passing variables into Tkinter button click event
SOLVED: Mutable vs nonmutable data types. Python passes arrays by reference, but array elements only by value. If I were passing in a single variable, this would have worked. command = lambda a = idx: BtnClicked( array[a] , a)) was changed to command = lambda a = idx: BtnClicked( array[a],a , a))d BtnClicked definition was also changed to now take in the index of the array, so now it is working as desired. def BtnClicked(obj,idx, value): obj[idx] = value More on reddit.com
🌐 r/learnpython
4
1
January 29, 2024
Tkinter button command using lambda to call a class method - how???
command=self.open_notebook will work, and is a better than using lambda in my opinion. You also need to move most of the code under def __init__ rather than where it is. class MainWidget: def __init__(self): root = Tk() root.geometry("400x400") search_frame = Frame(root) search_frame.pack() self.search_function = SearchFunction(search_frame) open_notebook_button = Button(root, text="Open", command=self.open_notebook) open_notebook_button.pack() root.mainloop() def open_notebook(self): self.search_function.get_emp_id() # and more stuff to add later More on reddit.com
🌐 r/Tkinter
4
4
September 11, 2022
🌐
Python Tutorial
pythontutorial.net › home › tkinter tutorial › tkinter command binding
Tkinter Command Binding - Python Tutorial
April 3, 2025 - The following program illustrates how to pass an argument to the callback function associated with the button command: import tkinter as tk from tkinter import ttk root = tk.Tk() def select(option): print(option) ttk.Button(root, text='Rock', command=lambda: select('Rock')).pack() ttk.Button(root, text='Paper',command=lambda: select('Paper')).pack() ttk.Button(root, text='Scissors', command=lambda: select('Scissors')).pack() root.mainloop()Code language: Python (python)
🌐
Python Programming
pythonprogramming.net › passing-functions-parameters-tkinter-using-lambda
Passing functions with Parameters in Tkinter using Lambda
class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self,parent) label = tk.Label(self, text="Start Page", font=LARGE_FONT) label.pack(pady=10,padx=10) button = tk.Button(self, text="Visit Page 1", command=lambda: qf("Check me out, I'm passing vars!")) button.pack()
🌐
Reddit
reddit.com › r/learnpython › how to use a tkinter button (call a function) that has an argument?
r/learnpython on Reddit: How to use a Tkinter button (call a function) that has an argument?
November 20, 2020 -

Hello everyone,

I have a Tkinter window that is defined in a class, and I have a function that gets a value from the Tkinter window.

I.E.

class newTopLevel(object):
    def __init__(self, root):
        self.newWindow = Toplevel(root)
        entry_1 = tk.Entry(self.newWindow).grid(row=0, column=1)
        self.newWindow.btn = tk.Button(self.newWindow,text='Enter',command=self.fun)
        self.newWindow.btn.grid(row=0,column=2)
    def fun(self):
        get_value=entry_1.get()

The issue here is entry_1 is not defined in my function. I normally don't have my Tkinter within a class, thus its a global and its properties (such as buttons and entry grids) are globals and they don't have to be defined. However in this case, now it does need to defined. I tried this:

def fun(self,entry_1):
        get_value=entry_1.get()

However, then I cannot use the button command to call it.

self.newWindow.btn = tk.Button(self.newWindow,text='Enter',command=self.fun(entry_1))

If I don't include the argument entry_1, then I'll get an error that fun has an argument and I haven't given any when using the button. I don't quite know how to use a Tkinter button that has arguments. Any help would be greatly appreciated!

🌐
Delft Stack
delftstack.com › home › howto › python tkinter › how to pass arguments to tkinter button command
How to Pass Arguments to Tkinter Button Command | Delft Stack
February 2, 2024 - from sys import version_info if version_info.major == 2: import Tkinter as tk elif version_info.major == 3: import tkinter as tk app = tk.Tk() labelExample = tk.Button(app, text="0") def change_label_number(num): counter = int(str(labelExample["text"])) counter += num labelExample.config(text=str(counter)) buttonExample = tk.Button( app, text="Increase", width=30, command=lambda: change_label_number(2) ) buttonExample.pack() labelExample.pack() app.mainloop() ... You don’t need any arguments in this example, therefore, you could leave the argument list empty and only give the expression.
🌐
TutorialsPoint
tutorialspoint.com › passing-arguments-to-a-tkinter-button-command
Passing arguments to a Tkinter button command
August 5, 2021 - In general, passing the arguments to a button widget allows the event to pick the arguments and use them further in the program. # Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() # Set the ...
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › python › tk_button.htm
Tkinter Button
from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") def helloCallBack(): msg=messagebox.showinfo( "Hello Python", "Hello World") B = Button(top, text ="Hello", command = helloCallBack) B.place(x=50,y=50) top.mainloop() When the above code is executed, it produces the following result − ·
🌐
Python Forum
python-forum.io › thread-35506.html
Button 'command' Argument Confusion
November 10, 2021 - I am confused by the 'command' argument for buttons. I have the following button defined: submitButton=tk.Button(top,text='Submit',command=submitData(top)).grid(row=rw,column=2,pady=5,sticky=tk.W)The command (submitData) is being executed immediately...
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 166751 › tkinter-button-widget-passing-parameter-to-function
python - tkinter button widget - passing parameter ... [SOLVED] | DaniWeb
January 7, 2009 - The Tkinter docs cover command callbacks and module naming in Python 3 (tkinter, not Tkinter) https://docs.python.org/3/library/tkinter.html. Widget references: Button(...).pack() returns None. If you need the button later, create it, then call pack() on a separate line. Here is an example how to use lambda to pass arguments in Tkinter's button command: import Tkinter as tk def getCond(par): firstCond = par #conditions.remove(firstCond) print firstCond #print conditions root = tk.Tk() firstCond = '' condNames = ['1', '2', '3', '4', '5', '6'] for item in condNames: …
🌐
ThisCodeWorks
thiscodeworks.com › python-how-to-pass-arguments-to-a-button-command-in-tkinter-stack-overflow-python › 61cc18b444c79c0015e8c15b
python - How to pass arguments to a Button command in Tkinter? - Stack Overflow | thiscodeWorks
another method to pass args in function without invoking fucntion https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter
🌐
TutorialsPoint
tutorialspoint.com › how-can-i-pass-arguments-to-tkinter-button-s-callback-command
How can I pass arguments to Tkinter button's callback command?
We will pass the label as the argument in the button command by using lambda function. #Import necessary Library from tkinter import * from tkinter import ttk #Create an instance of tkinter window win= Tk() #Set the geometry of tkinter window win.geometry("750x250") #Define the function to ...
🌐
AIMosta
aimosta.com › Blogt › blogt-15.html
The Button Command with Parameters
Now, to define the property command of the button (the function that will be called), we will use lambda that will be equal to the call of the changeColor function with our button as a parameter.
🌐
Python Tutorial
pythontutorial.net › home › tkinter tutorial › tkinter button
Tkinter Button - Python Tutorial
April 3, 2025 - This is called the command binding in Tkinter. ... The master is the parent widget on which you place the button. The **kw is one or more keyword arguments you use to change the appearance and behaviors of the button.
🌐
sqlpey
sqlpey.com › python › tkinter-button-command-arguments-techniques
Tkinter Button Command Arguments: Techniques for Passing Data to Callbacks
October 29, 2025 - import tkinter as tk def display_text(text_content): print(f"Button Text: {text_content}") top = tk.Tk() texts_to_show = ["Text One", "Text Two", "Text Three"] buttons = [] for idx, content in enumerate(texts_to_show): # Crucial: Assigning 'ztemp=content' captures the value at creation time btn = tk.Button(top, text=content, command=lambda ztemp=content: display_text(ztemp)) btn.pack(side=tk.LEFT, padx=5) top.mainloop() The partial function from Python’s standard functools library allows you to create a new callable object where some arguments of an existing function are pre-filled. This res
🌐
Python.org
discuss.python.org › python help
How to call same function with different argument given from list in tkinter button command option - Python Help - Discussions on Python.org
November 8, 2019 - from tkinter import * def fun(nm): msg= 'hello {}'.format(nm) print(msg) master=Tk(className="testing") list=[1,2,3,4] for x in list: para=x Button(master, text=x, command=lambda:fun(x)).pack(side='left') master.mainloop() getting output hello 4 every time
🌐
Python GUIs
pythonguis.com › tutorials › getting started with tkinter › create buttons in tkinter
Button Widgets in Tkinter
July 13, 2022 - We create the turn_off, vol_up, and vol_down buttons in a similar fashion and pack them with pack(). Only one of these buttons, turn_off, does something because we used the keyword command argument to make the button call root.destroy(), which closes the root window immediately:
🌐
15. The Menu widget
anzeljg.github.io › rin2 › book2 › 2405 › docs › tkinter › button.html
7. The Button widget
Calls the button's command callback, and returns what that function returns. Has no effect if the button is disabled or there is no callback. Next: 8. The Canvas widget · Contents: Tkinter 8.5 reference: a GUI for Python · Previous: 6. Exception handling ·
🌐
Reddit
reddit.com › r/learnpython › passing variables into tkinter button click event
r/learnpython on Reddit: Passing variables into Tkinter button click event
January 29, 2024 -

I'm close, but I think I'm missing something fundamental.

I'm programatically building some tkinter buttons and trying to get them to set a variable to some value (in this case, their own array index).

from tkinter import *
btnarray = [] array = []
def BtnClicked(obj, value): 
    obj = value
def CreateWindow():
    for idx in range(10):
        array.append(0)
        btnarray.append(Button(root, text = f"Button {idx}", command = lambda a = idx: BtnClicked( array[a] , a)))
        btnarray[-1].pack()
root = Tk()
CreateWindow()
while True:
    root.update()     

structure is representative of the application I inherited and am trying to alter. Why isn't it writing the values to array? if I break inside 'BtnClicked', obj gets the value written, but that somehow doesn't pass back to array.

Thanks!