einelementige tupel extrahieren
Verfasst: Dienstag 3. April 2007, 02:34
ich hab einen int in einer tupel (von Tkinter.Listbox.curselection())
wie krieg ich ihm den da raus?
wie krieg ich ihm den da raus?
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
In [1]: t = (42,)
In [2]: t[0]
Out[2]: 42
Code: Alles auswählen
>>> t = (42,)
>>> i ,= t
>>> i
42
Code: Alles auswählen
def download(index):
index = index[0]
print 'downloading', file_locations[index]
results.delete(index)
Code: Alles auswählen
Traceback (most recent call last):
File "lib-tk/Tkinter.py", line 1348, in __call__
return self.func(*args)
File "getit/simple.py", line 116, in <lambda>
results.bind('<Button-1>', lambda n: download(results.curselection()))
File "getit/simple.py", line 75, in download
print 'downloading', file_locations[index]
TypeError: list indices must be integers
Code: Alles auswählen
results.bind('<Button-1>', lambda n: download(results.curselection()))
superb, just what i needed. thxSchon mal überlegt, das Tutorial durchzuarbeiten? Das was du fragst steht genau so im Tuturial drin.
Code: Alles auswählen
In [20]: root = tk.Tk()
In [21]: lb = tk.Listbox(root)
In [22]: lb.insert(0, 'a', 'b', 'c')
In [23]: lb.pack()
In [24]: lb.curselection()
Out[24]: ('1',)