Hi! Re: http://www.daniweb.com/forums/post868247.html#post868247, the example provided by sneekula is helpful, but I need to return the result of the ButtonRelease-1 to main; the only way I could figure out to do this was using a global; is there a better way? Thanks again!

but I need to return the result of the ButtonRelease-1 to main

I for one have no idea what this means as the URL referenced contains many examples.

So much for the usefulness of Permalink; here's the code to which I was referring. Thanks!

# create a scrollable listbox using Tkinter
# load the listbox with tasty cheese data
# and select your favorite cheese with the mouse
# with Python3 use import tkinter as tk

import Tkinter as tk

def get_list(event):
"""
function to read the listbox selection
and put the result in a label widget
"""
# get selected line index
index = listbox.curselection()[0]
# get the line's text
seltext = listbox.get(index)
# put the selected text in the label
label = seltext

root = tk.Tk()
root.title("Cheeses")
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("180x300+30+50")

# create a label (width in characters)
s = "Click on a cheese"
label = tk.Label(root, text= s, width=15)
label.grid(row=0, column=0)

# create a listbox (height in characters/lines)
# give it a nice yellow background (bg) color
listbox = tk.Listbox(root, height=15, bg='yellow')
listbox.grid(row=1, column=0)

# the Tkinter listbox does not automatically scroll, you need
# to create a vertical scrollbar to the right of the listbox
yscroll = tk.Scrollbar(command=listbox.yview, orient=tk.VERTICAL)
yscroll.grid(row=1, column=1, sticky='n'+'s')
listbox.configure(yscrollcommand=yscroll.set)

cheese_list = [
'Feta', 'Limburger', 'Camembert', 'Roquefort', 'Edam',
'Romadur', 'Liptauer', 'Dubliner', 'Gouda', 'Gorgonzola',
'Jarlsberg', 'Golka', 'Garrotxa', 'Swiss', 'Quesillo',
'Emmentaler', 'Appenzeller', 'Raclette', 'Asiago', 'Zuvi',
'Ricotta', 'Mozzarella', 'Munster', 'Parmesan']

# load the listbox
for item in cheese_list:
listbox.insert('end', item)

# use left mouse click on a list item to display selection
listbox.bind('<ButtonRelease-1>', get_list)

root.mainloop()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.