when i click a row of my list box i want to show value in my drop down list.
def callback(selection):
selected = selection
return selected
edumenu=StringVar()
eduvalue=StringVar()
edumenu=OptionMenu(window, eduvalue, "red", "blue", "green",command=callback)
edumenu.grid(row=1,column=4)
eduvalue.set("red")
def get_selected_row(event):
global selected_data
eduvalue.set(callback(edumenu))
list1.bind("<<ListboxSelect>>", get_selected_row)
it returns the data type of value in option menu not text value
Does this solve your problem.
from tkinter import *
# create a root window.
top = Tk()
# create listbox object
listbox = Listbox(top, height = 10,
width = 15,
)
# Define the size of the window.
top.geometry("300x250")
# Define a label for the list.
label = Label(top, text = " FOOD ITEMS")
# insert elements by their
# index and names.
listbox.insert(1, "Nachos")
listbox.insert(2, "Sandwich")
listbox.insert(3, "Burger")
listbox.insert(4, "Pizza")
listbox.insert(5, "Burrito")
# pack the widgets
label.pack()
listbox.pack()
def callback(selection):
selected = selection
return selected
edumenu=StringVar()
eduvalue=StringVar()
edumenu2=OptionMenu(top, eduvalue, "red", "blue", "green",command=callback)
edumenu2.pack()
eduvalue.set("red")
def get_selected_row(event):
global selected_data
eduvalue.set(callback(listbox.get(listbox.curselection())))
listbox.bind("<<ListboxSelect>>", get_selected_row)
# Display untill User
# exits themselves.
top.mainloop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.