S
S
shshshshkolnik2015-11-03 17:18:28
Python
shshshshkolnik, 2015-11-03 17:18:28

Dropdown menu, listbox and python - how to be?

Is it possible to create a drop-down menu using the standard tkinter library (yes, at least this: b125a3e14a.jpg) and how to "get" the selected option from it? And if not, how can I "get" the selected item from the Listbox? (.get() throws an error)
PS: if it doesn't make it difficult - with examples, please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ekizare, 2015-11-03
@shshshshkolnik

Create a list, bind a function to it and perform operations in it. Example:

root = Tk()
root.wm_geometry("%dx%d+%d+%d" % (400, 150, 20, 40))
listbox_items = ['Раз', 'Два', 'Три']


def select_item(event):
    value = (listbox.get(listbox.curselection()))
    print(value)


listbox = Listbox(root, width=40, height=5, font=('times', 13))
listbox.bind('<<ListboxSelect>>', select_item)
listbox.place(x=15, y=15)

for item in listbox_items:
    listbox.insert(END, item)
root.mainloop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question