How do I get the contents of a Tk listbox without selecting each item?
How do I get the contents of a Tk listbox without selecting each item?
I have a Tk listbox widget (chosenItems) that gets populated with selected items from another listbox (possibleItems). When a user has chosen all the items they want to manipulate or change, I have a button (Apply) that applies a set of transformations to the list of "chosenItems". To make this work, I need to collect all the entries of the Tk listbox.
How do I do that and generate a list for those items?
2 Answers
2
Off the top of my head, not tested: you can specify a -listvariable
, which will hold all items in the list, or use the get
subcommand, e.g. $myListbox get 0 end
.
-listvariable
get
$myListbox get 0 end
The Tk listbox supports a get
command, so something like:
get
set lbentries [.l get 0 end]
should give you a list of all the entries in the list box (where .l
is the listbox widget command).
.l
Alternately, you could use the -listvariable
option to the widget and manage the contents of the list box via a global variable.
-listvariable
Take another close read of the listbox manual page and you'll see the options available to you.
You're missing out: tcl.tk/man -- you'll definitely want to bookmark the docs for your version.
– glenn jackman
Jun 29 at 20:59
Tcl is well documented and the official documentation is kept up to date. Invariably, books fall behind despite how helpful they may be in getting you started. Also the Tcl wiki is a wealth of information.
– andy mango
Jun 29 at 21:12
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Manual page? Are there man pages for TCL/Tk widgets? Or is this in a book? I'm currently using Brent Welch's "Practical Programming in Tcl and Tk", but it seems really out of date.
– Stephen Alter
Jun 29 at 20:06