How to get the text of the pressed button in tkinter?

There is a program cinema. The button value is number of auditorium in which you need to go. The cinemas themselves are formed by the array. How can I pass the text of the button which is clicked into a variable?
Tried to do like the example with the seats in the cinema through the library re, and turned. But how can I pass those values to variables without such crutches?

from tkinter import *
import re


class Kino():
 def __init__(self):
 self.mas = []
 names = []
 for i in range(10):
 self.name = "Cinema" + str(i)
names.append(self.name)
 self.root = Tk()
self.root.geometry("300x500")
 self.root.title("Booking")
 for i in range(10):
 self.ss = i
 self.but = Button(self.root. text=names[i], background="#ccc", foreground="#555", padx="40", pady="8",
 font="16" width="12", command=self.for_knopki)
self.but.pack()
 self.board = list(range(1, 10))
self.root.mainloop()

 def changeBut(self, event):
 event.widget["background"] = "#ffc801"
 abs = re.search("button(\d+)?", str(event.widget))
self.mas.append(abs[1])

 def for_knopki(self):
print(self.ss)
 self.root = Tk()
 for i in range(10):
 for j in range(10):
 self.but = Button(self.root, background="#ccc", foreground="#555", padx="20", pady="8", font="16",
width="1")
 asd = str(i) + str(j)
 if asd in self.mas:
 self.but["bg"] = "#ffc801"
self.but.configure()
 self.but["text"] = str(j + 1)
 self.but.bind("<Button-1>", self.changeBut)
 self.but.grid(row=i, column=j)
 self.lab = Label(self.root, text="the number" + str(i))
 self.lab.grid(row=i, column=(j + 1))

if __name__ == '__main__':
 Kino()
March 20th 20 at 11:54
1 answer
March 20th 20 at 11:56
Solution
def on_click(event):
 button_text = event.widget.cget('text')

button = Button(root, text='Hello')
button.bind('<Button-1>', on_click)
Thank you - Laverna.Cronin commented on March 20th 20 at 11:59

Find more questions by tags PythonTkinter