I am writing a GUI with Python TKinter where I have a grid of some 24 buttons which I have created using a loop (not individually). Is there any way in which I can get the Text of the button that I pressed.
Since it is in loop, a callback function even with lambda is not helping me. I don't wish to write separate code for, what happens when each different button is pressed. I just need to know the text of the corresponding button so that I could initiate another generic function which works with that text only.
ps: I am able to do the same task but with List and curselection() and don't want it this way.
self.num = 11
for r in range(0,5):
for c in range(0,3):
R = r; C = c
resNum = "Ch0"+str(self.num);
self.button1_rex = tk.Button(self.frame, text = resNum,font=("Helvetica", 14), justify = CENTER,width = 20, command = self.new_window)
self.button1_rex.grid(row=R, column=C, sticky=W)
self.num = self.num+1
self.new_window is the function that opens a new window and needs to do other functionalities based on the button number (like "Ch011" etc)