Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

display item in a listbox

30 views
Skip to first unread message

mluc

unread,
Apr 10, 2017, 5:41:08 PM4/10/17
to
I have a list of 4 elements and I want to display them in rows ( 4 rows) in my listbox, but when I append those elemts to my listbox, they show up in a single
ros. Can somebody help me to figure out what is wrong?
I have :
set lv { a b c d}
listbox .lbx -listvariable lv
.lbx insert end $lv

my values are displayed in my listbox as "a b c d" instead of
a
b
c
d

thanks for any comment
ml

Rich

unread,
Apr 10, 2017, 5:50:34 PM4/10/17
to
You inserted only one "element", a full list, which was converted to a
string and put into a single row.

Note, from the documentation:

pathName insert index ?element element ...?

See that part about "?element element ...?" That means you have to do
your insert like this:

.lbx insert end a b c d

I.e., separate elements.

If your elements are already in a list, and you are using 8.5 or
greater, you can convert the list into separate parameters with the
expand: {*} operator.

.lbx insert end {*}$lv

{*} treats $lv as a list, and places each internal list element onto
.lbx's command line as a separate item.

Gerald W. Lester

unread,
Apr 10, 2017, 6:18:55 PM4/10/17
to
Well:
1) the code you post does not display what you claim, instead it displays:
a
b
c
d
a b c d
2) you really should not have the space after the "{" on the set line.
3) if you are using a listvariable, you can just change it and not need the
inserts
4) as mentioned in another post, you are inserting a single element. You
should be doing: .lbx insert end {*}$lv

I also expect you did not copy your code as you it really is. In
particularly I expect that the listbox command is inside of a procedure and
the "lv" is local to that procedure. Please reread the section on
-listvariable (hint, it always refers to a global).

--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

mluc

unread,
Apr 10, 2017, 6:52:07 PM4/10/17
to
thaks all.
my lv is a list of elements returned from a previous proc. so I use
-listvariable lv to manipulate each element later.
it is any difference if I used SpecTcl to create my gui?
thanks

mluc

unread,
Apr 10, 2017, 7:08:36 PM4/10/17
to
for my script, I have to use -listvariable. insert is not working for me
thanks

Alexandru

unread,
Apr 10, 2017, 7:22:43 PM4/10/17
to
Hi,

I don't have the feeling you understood the previous explanations. But anyhow, at least your code works now...
0 new messages