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.
Tutorialspoint
tutorialspoint.com › python › tk_button.htm
Tkinter Button
options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas. Following are commonly used methods for this widget − · Try the following example yourself − · 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 Tutorial
pythontutorial.net › home › tkinter tutorial › tkinter button
Tkinter Button - Python Tutorial
April 3, 2025 - The button’s command is assigned to a lambda expression that closes the main window. The following program shows how to display an image button. To practice this example, you need to download the following image first: Just right-click and save it into a folder that is accessible from the following program, e.g., assets folder: import tkinter as tk from tkinter import ttk from tkinter.messagebox import showinfo # main window root = tk.Tk() root.geometry('300x200') root.resizable(False, False) root.title('Image Button Demo') def handle_click(): showinfo( title='Information', message='Download button clicked!'
Videos
Button Command in Tkinter | Button Command Function With ...
26:28
An overview of the tkinter buttons (+using them with tkinter ...
06:15
Tkinter Tutorial For Beginners - Buttons in Tkinter - YouTube
05:38
Pass argument to Tkinter Button Command function - YouTube
08:04
Using button functions with arguments in tkinter - YouTube
Create Modern Buttons With Tkinter in Python | Tkinter GUI ...
GeeksforGeeks
geeksforgeeks.org › python › python-creating-a-button-in-tkinter
Python Tkinter - Create Button Widget - GeeksforGeeks
August 22, 2025 - invoke(): 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. In this example, below code uses the tkinter library to create a graphical user interface. It defines a function, button_clicked(), which prints a message when called.
Python Course
python-course.eu › tkinter › buttons-in-tkinter.php
3. Buttons in Tkinter | Tkinter | python-course.eu
import tkinter as tk def write_slogan(): print("Tkinter is easy to use!") root = tk.Tk() frame = tk.Frame(root) frame.pack() button = tk.Button(frame, text="QUIT", fg="red", command=quit) button.pack(side=tk.LEFT) slogan = tk.Button(frame, text="Hello", command=write_slogan) slogan.pack(side=tk.LEFT) root.mainloop()
Top answer 1 of 14
426
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.
2 of 14
161
This can also be done by using partial from the standard library functools, like this:
from functools import partial
#(...)
action_with_arg = partial(action, arg)
button = Tk.Button(master=frame, text='press', command=action_with_arg)
Stack Overflow
stackoverflow.com › questions › 75542846 › python-tkinter-button-commands
python tkinter button commands - Stack Overflow
import tkinter from play_function import * window = tkinter.Tk() screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() window.config ( width = screen_width ) window.config ( height = screen_height ) window.config ( background = "black" ) title = tkinter.Label ( window , text = "Scrabble" , background = "black" , foreground = "green" , font = ( "Comic Sans MS" , 200 ) ) title.pack() play_button = tkinter.Button ( window , text = "PLAY" , background = "blue" , foreground = "black" , font = ( "Comic Sans MS" , 80 ) ) exit_button = tkinter.Button ( window , text = "
Python Tutorial
pythontutorial.net › home › tkinter tutorial › tkinter command binding
Tkinter Command Binding - Python Tutorial
April 3, 2025 - Note that you pass the callback without parentheses () within the command option. Otherwise, the callback would be called as soon as the program runs. The following program illustrates how to associate the button_clicked callback function with the Button widget: import tkinter as tk from tkinter import ttk root = tk.Tk() def button_clicked(): print('Button clicked') button = ttk.Button(root, text='Click Me', command=button_clicked) button.pack() root.mainloop()Code language: Python (python)
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 ·
GeeksforGeeks
geeksforgeeks.org › how-to-pass-arguments-to-tkinter-button-command
How to Pass Arguments to Tkinter Button Command? - GeeksforGeeks
October 3, 2022 - Prerequisites: Tkinter Python's Tkinter module offers the Button function to create a button in a Tkinter Window to execute any task once the button is clicked. The task can be assigned in the command parameter of Button() function. Given below are various methods by which this can be achieved.
GitHub
github.com › Akuli › tkinter-tutorial › blob › master › buttons.md
tkinter-tutorial/buttons.md at master · Akuli/tkinter-tutorial
As usual, all possible options are listed in the ttk_button(3tk) manual page. One of these options is command, and if we set it to a function it will be ran when the button is clicked. This program prints hello every time we click its button: import tkinter from tkinter import ttk def print_hello(): print("hello") root = tkinter.Tk() big_frame = ttk.Frame(root) big_frame.pack(fill='both', expand=True) button = ttk.Button(big_frame, text="Print hello", command=print_hello) button.pack() root.mainloop()
Author Akuli
CustomTkinter
customtkinter.tomschimansky.com
Official Documentation And Tutorial | CustomTkinter
CustomTkinter is a python desktop UI-library based on Tkinter, which provides modern looking and fully customizable widgets. With CustomTkinter you'll get a consistent look across all desktop platforms (Windows, macOS, Linux). Simple · Object Oriented · import customtkinter def button_callback(): print("button clicked") app = customtkinter.CTk() app.geometry("400x150") button = customtkinter.CTkButton(app, text="my button", command=button_callback) button.pack(padx=20, pady=20) app.mainloop() import customtkinter class App(customtkinter.CTk): def __init__(self): super().__init__() self.geometry("400x150") self.button = customtkinter.CTkButton(self, text="my button", command=self.button_callbck) self.button.pack(padx=20, pady=20) def button_callbck(self): print("button clicked") app = App() app.mainloop() With just a few lines of code, you already get a fully working program:
Python Basics
pythonbasics.org › home › tkinter › tkinter buttons (gui programming)
Tkinter buttons (GUI Programming) - pythonbasics.org
from tkinter import * class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master # widget can take all window self.pack(fill=BOTH, expand=1) # create button, link it to clickExitButton() exitButton = Button(self, text="Exit", command=self.clickExitButton) # place button at (0,0) exitButton.place(x=0, y=0) def clickExitButton(self): exit() root = Tk() app = Window(root) root.wm_title("Tkinter button") root.geometry("320x200") root.mainloop()
Tk Tutorial
tk-tutorial.readthedocs.io › en › latest › button › button.html
Button — Tk tutorial 2020 documentation
import tkinter as tk root = tk.Tk() root.title("Feet to meters") Two of the widgets, the entry widget and the label widget, have special StringVar variables: ... tk.Entry(root, width=10, textvariable=feet).pack() tk.Button(root, text='Convert feet to meters', command=calculate).pack() tk.Label(root, textvariable=meters).pack()
Tcl Wiki
wiki.tcl-lang.org › page › tkinter.Button
tkinter.Button
If "option" is specified, then ... (this list will be identical to the corresponding sublist of the value returned if no option is specified). If **options are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the method returns an empty string. Option may have any of the values accepted by the Button ...
Python Guides
pythonguides.com › python-tkinter-button
How To Create Buttons In Python With Tkinter?
March 19, 2025 - In this tutorial, I have explained how to create buttons in Python with Tkinter. I discussed how to customize button appearance, handle button events, work with button states , and retrieve button text. I also coved Tkinter button style, button command, button command argument, button shape, ...
Stack Overflow
stackoverflow.com › questions › 50787864 › how-do-i-make-a-tkinter-button-in-an-list-of-buttons-return-its-index
python - How do I make a tkinter button in an list of buttons return its index? - Stack Overflow
from tkinter import * root = Tk() files = [] #creates list to replace your actual inputs for troubleshooting purposes btn = [] #creates list to store the buttons ins for i in range(50): #this just popultes a list as a replacement for your actual ...