Label Variables

Sam Garson peanut.sam at googlemail.com
Mon Dec 17 22:46:27 EST 2007


Hi again.

I am trying to get the text of the selection in a list box and put into a
variable, which is put into a label. i.e., whatever is selected will show in
the label.

However, because at the beginning there is nothing in the listbox (and
therefore no selection), the tuple returned by curselection() is (),
therefore when i try and get() from the linenumber in this tuple, the index
is "out of range"

here is the section of the program:

box = Listbox(root, bg = '#ebe9ed', relief = 'groove', height = 15)
box.grid(row = 2, columnspan = 2, sticky = W+E, padx = 3)
box.bind("<Double-Button-1>", DeleteCurrent)

v = StringVar()
number = box.curselection()
v.set = (box.get(int(number[0])))
print number

current = Label(root, textvariable = v)
current.grid(row = 3, columnspan = 2, sticky = W+E, padx = 3)

and here is the error:

Traceback (most recent call last):
  File "C:\My Documents\My Python\Notes.py", line 27, in <module>
    v.set = (box.get(int(number[0])))
IndexError: tuple index out of range

How can i get it to only take the variable when i have selected something,
or any other solution!

Thanks,

Sam

-- 
I intend to live forever - so far, so good.

SaM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071218/3793ee3f/attachment.html>


More information about the Python-list mailing list