You can simply do:

my_text = my_button['text']

Tkinter allows you to access any option of a widget this way (height, width, text, etc.)


If you need this as a method call, you can use .cget:

my_text = my_button.cget('text')

Note that this method is available on all standard Tkinter widgets.

Answer from user2555451 on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com β€Ί get-the-text-of-a-button-widget-in-tkinter
Get the text of a button widget in Tkinter
April 21, 2021 - #Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a button button= ttk.Button(win, text="My Button") button.pack() #Get the text of Button mytext= ...
Discussions

Python tkinter how to get text from button I clicked on - Stack Overflow
I have code like this (just part of a code). I need when someone click on the button that is in list named buttonList then it gets buttons text. This is code how I make render of those buttons. Its More on stackoverflow.com
🌐 stackoverflow.com
python - Print the clicked button's text tkinter - Stack Overflow
Additionally you can use print(b[d].cget('text')) if using the list is preferred . Since the button objects are appended to a list you can use that to get the text from them. More on stackoverflow.com
🌐 stackoverflow.com
python - How to get a button text in a function - tkinter? - Stack Overflow
In the code below, this is done by separating the Button creation from the configuring its command option, which is now done after they all exist. from tkinter import * root = Tk() def clicked(btn): btn_text = btn.cget('text') message = Label(root, text=f'You clicked button "{btn_text}".') ... More on stackoverflow.com
🌐 stackoverflow.com
May 29, 2021
Python 3, Tkinter, How to update button text - Stack Overflow
How can I make it so that the text on the button is updated? My best idea so far has been to delete the buttons then print them again, but that only deletes one button. Here's what I have so far: from tkinter import * BoardValue = ["-","-","-","-","-","-","-","-","-"] window = Tk() ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python Course
python-course.eu β€Ί tkinter β€Ί buttons-in-tkinter.php
3. Buttons in Tkinter | Tkinter | python-course.eu
The following script shows an example, where a label is dynamically incremented by 1 until a stop button is pressed: import tkinter as tk counter = 0 def counter_label(label): counter = 0 def count(): global counter counter += 1 label.config(text=str(counter)) label.after(1000, count) count() root = tk.Tk() root.title("Counting Seconds") label = tk.Label(root, fg="dark green") label.pack() counter_label(label) button = tk.Button(root, text='Stop', width=25, command=root.destroy) button.pack() root.mainloop()
🌐
Python Assets
pythonassets.com β€Ί posts β€Ί button-in-tk-tkinter
Button in Tk (tkinter) | Python Assets
February 15, 2022 - A button might have an image besides the text. You can even have a single image without text. We have already seen that the button text is indicated via the text argument when creating an instance of ttk.Button.
🌐
DaniWeb
daniweb.com β€Ί programming β€Ί software-development β€Ί threads β€Ί 240519 β€Ί getting-text-values-from-buttons-in-tkinter-to-make-a-version-of-minesweeper
Getting text values from buttons in Tkinter to make a version of Minesweeper
November 23, 2009 - Tip: keep a separate 2D board model for mines and counts, and drive UI updates from that model. For flags, you can bind right-click (<Button-3>) to toggle a flagged state; left-click remains the reveal action (Tkinter bind, Button widget).
Top answer
1 of 1
4

Ok so here is an example using a class to perform what I think it is you are asking.

You want to use lambda in your command and assign the value of text to a variable. Then you pass that variable to the getTest(self, text) method to be able to print your button.

From your comment

Whole code is not need i just need way to get buttons text nothing else

I have created a bit of code to illustrate what you are wanting.

EDIT: I have added code that will allow you to change the configs of the button as well.

import tkinter as tk

# created this variable in order to test your code.
seznamTextu = ["1st Button", "2nd Button", "3rd Button", "4th Button", "5th Button"]

class MyButton(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent
        self.obsahOkna()
    def obsahOkna(self):

        radek = 0
        bunka = 0
        for i in range(5):
            btn = tk.Button(self.parent, text=seznamTextu[i])
            btn.config(command= lambda t=seznamTextu[i], btn = btn: self.getText(t, btn))
            # in order for this to work you need to add the command in the config after the button is created.
            # in the lambda you need to create the variables to be passed then pass them to the function you want.
            btn.grid(row=radek, column=bunka)

            bunka += 1
            if bunka == 2 : # changed this variable to make it easier to test code.
                bunka = 0
                radek +=1

    def getText(self, text, btn):
        btn.configure(background = 'black', foreground = "white")
        print("successfully called getText")
        print(text)


if __name__ == "__main__":
    root = tk.Tk()
    myApp = MyButton(root)


    root.mainloop()

Here is the result of running the program and pressing a couple buttons.

Find elsewhere
🌐
Universidad de Granada
ccia.ugr.es β€Ί mgsilvente β€Ί tkinterbook β€Ί button.htm
The tkinter Button Widget
The text can contain newlines. If the bitmap or image options are used, this option is ignored (unless the compound option is used). (text/Text) ... Associates a tkinter variable (usually a StringVar) to the button. If the variable is changed, the button text is updated.
🌐
Python Examples
pythonexamples.org β€Ί python-tkinter-change-button-text-dynamically
Python Tkinter - Change Button Text Dynamically
You can change the text property of Tkinter button using the reference to the button and 'text' option as index. The pseudo code would be button['text'] = 'new value'.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί how-to-check-which-button-was-clicked-in-tkinter
How to check which Button was clicked in Tkinter ? - GeeksforGeeks
July 29, 2024 - In this example, if the text 'It is an apple' is printed on the screen, we get to know 'Apple' button is pressed, else when 'It is a banana' is printed on the screen, we get to know 'Banana' button is pressed. ... # Import the library tkinter from tkinter import * # Create a GUI app app = Tk() # Create a function with one parameter to indicate which button was clicked def which_button(button_text): # Printing the text when a button is clicked print(f"Button clicked: {button_text}") # Creating and displaying of button b1 b1 = Button(app, text="Apple", command=lambda: which_button("Apple")) b1.grid(padx=10, pady=10) # Creating and displaying of button b2 b2 = Button(app, text="Banana", command=lambda: which_button("Banana")) b2.grid(padx=10, pady=10) # Make the infinite loop for displaying the app app.mainloop()
🌐
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. Here are the common configurations of the button widget: button = ttk.Button( master, text=label, command=fn )Code language: Python (python)
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί tk_button.htm
Tkinter Button
These buttons can display text or images that convey the purpose of the buttons. You can attach a function or a method to a button which is called automatically when you click the button. Here is the simple syntax to create this widget βˆ’ ... 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 βˆ’ ... 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()
🌐
CopyProgramming
copyprogramming.com β€Ί howto β€Ί read-text-from-button-tkinter-duplicate
How to Get Button Text in Tkinter Python - Button text in tkinter python
January 25, 2026 - ... Getting the text of a button in Tkinter is straightforward using the cget('text') method or direct dictionary access like button['text']. This works for both classic Tkinter buttons and themed ttk buttons, allowing you to read dynamic labels in event handlers or for validation.
🌐
Quora
quora.com β€Ί How-do-I-get-the-text-from-the-entry-in-Tkinter
How to get the text from the entry in Tkinter - Quora
Answer (1 of 3): Ok try this and see if it works : You will notice in this code I used the grid system instead of the pack one. [code]from tkinter import * from tkinter import ttk # also import the themed tkinter for good looking widgets (not obligatory) class Widget: def __init__(self): wi...