1

I'm trying to figure out a way to get the text of the widget beside the button I pressed. For Example, when I click the first button I want it to print '0', if it's the second button, then print '1'.enter image description here

#--------CREATE TREEVIEW HEADER-------#
for x,y in header:
    entry = customtkinter.CTkEntry(scrollable_frame,justify='center')
    entry.insert(0,y)
    entry.configure(state='readonly')
    if y.lower() == 'phone number':
        entry.grid(row=0,column=x,ipadx=80,pady=5)
    else:
        entry.grid(row=0,column=x,pady=5)

#--------CREATE ENTRYBOXES UNDER "PHONE NUMBER" & BUTTONS UNDER "STATUS"---------#
for x in range(16):
    entry=customtkinter.CTkEntry(scrollable_frame,justify='center')
    entry.insert(0, x)
    entry.configure(state='readonly')
    entry.grid(row=x+3, column=0, ipadx=80,pady=0)

for x in range(16):
    button=customtkinter.CTkButton(scrollable_frame,text='Click Me',command=get_number)
    button.grid(row=x+3, column=1,pady=0)




if __name__ == '__main__':
    root.mainloop()
Wayne Gan
  • 39
  • 1
  • 3
  • 2
    To get the text of the widget beside the button pressed, you can pass the corresponding entry widget as an argument to the get_number function using a lambda function. For example: `button = Button(text="Click Me", command=lambda entry=entry: get_number(entry)) ` `def get_number(entry): print(entry.get()) ` – Collaxd Feb 19 '23 at 15:09

0 Answers0