0

I wonder if this is possible. Imagine I have a listbox L1 with three items. If I select item one with single click, I want to get L1.curselection() to be ('0',), then if I select item three (without holding control or shift) I want to get L1.curselection() now updated so I get the output of ('2',).

Is this possible with listbox widget in Tkinter. Is my understanding of curselection() correct?

I am trying to build something like a file viewer.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
user3056783
  • 2,265
  • 1
  • 29
  • 55
  • What make you doubt about your understanding? May I suggest to write a _very minimal_ program to convince you. And if this one doesn't work as expected (or as _I_ understood _you_ were expecting) -- feel free to ask an other question. – Sylvain Leroux Aug 23 '14 at 22:06

1 Answers1

0

Is this possible with listbox widget in Tkinter

Yes

Is my understanding of curselection() correct?

Yes, probably


If I understand you correctly, the is exactly the way it is supposed to work. To quote http://effbot.org/tkinterbook/listbox.htm#Tkinter.Listbox.curselection-method:

curselection()

Gets a list of the currently selected alternatives. The list contains the indexes of the selected alternatives (beginning with 0 for the first alternative in the list). In most Python versions, the list contains strings instead of integers. Since this may change in future versions, you should make sure your code can handle either case. See the patterns section for a suggested solution.

Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125