I have a customtkinterGUI where I make some labels with the text: namen. Within each label I have an optionmenu. After selecting the option, it uses a callback function with "selection" as input, but in I want to make it in such a way that when I select an option, then it returns the selection, but also the name in which label that selection was made.
This is my piece of code:
def callback(selection):
if selection != "Kies data vorm":
print(selection, type(selection))
def make_name_labels(namen, iterator):
global over_frame, optionmenu1st_level
over_frame = customtkinter.CTkFrame(master=root)
over_frame.place(x=80, y=50 + (iterator-1)*45, height=40, relwidth=0.95)
namen_label = customtkinter.CTkLabel(master=over_frame, text=namen)
namen_label.place(rely=0.5, x=10, anchor=tkinter.W)
optionmenu1st_level = customtkinter.CTkOptionMenu(master=over_frame, values=["", "Tekst", "Plaatje","code: code128","code: qrcode","code: datamatrix"], command=callback)
optionmenu1st_level.place(rely=0.5, relheight=0.9, x=150, anchor=tkinter.W)
optionmenu1st_level.set("Kies data vorm")
An example, when I select "Tekst" in label with name: this_name, the callback function takes these two as parameters. To make it visible: