0

I want to make a 4x5 buttons list so I did this in python:

for i in range(4):
    seats_btn_row = []
    for j in range(5):
        btn = Button(self.fra_seats, text = str(i+1) + "-" + str(j+1), image = self.img_seat_takable, command = self._on_button_clicked
        btn.bind("<Button-1>", self.callback)
        btn.grid(row = i+1, column = j+1)
        seats_btn_row.append(btn)
    self.seats_btn_list.append(seats_btn_row)
self.fra_seats.grid(row = 2, column = 1)

it looks like this:

enter image description here

and in the self._on_button_clicked function, I want to know which button I have pressed(the row and the column of the button), actually I tried to get the button's text attributes but failed to make it.

Is there any way to know some information of the ButtonPressEvent's source button?

I have tried .bind function and command parameter

Gonzalo Garcia
  • 6,192
  • 2
  • 29
  • 32
jiengup
  • 3
  • 4
  • Read [Get the text of a button if clicked](https://stackoverflow.com/a/6205482/7414759) – stovfl Dec 03 '19 at 15:33
  • It definitly works! Thank you very much, have a good day! :) – jiengup Dec 04 '19 at 01:11
  • Does this answer your question? [Working on a way to return the text of a button after the button is clicked in tkinter](https://stackoverflow.com/questions/6195702/working-on-a-way-to-return-the-text-of-a-button-after-the-button-is-clicked-in-t) – stovfl Dec 04 '19 at 08:07

0 Answers0