Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox with a list 1

Status
Not open for further replies.

czins

Technical User
Jan 14, 2002
37
CH
Hello,

I need to display a listbox of a list variable crated with with lappend (cliste). The command "puts" shows the rows enclosed in brackets {} but I cant get the list displayed in the listbox.

Please check the command: .m_outp.lb $cliste in my code.

Can I have some advise please ?

proc Create_output {cliste} {

toplevel .m_outp
frame .m_outp.f
listbox .m_outp.lb -selectmode single -height 10
scrollbar .m_outp.sb -command [list .m_outp.lb yview]
.m_outp.lb configure -yscrollcommand [list .m_outp.sb set]

.m_outp.lb $cliste

pack .m_outp.lb .m_outp.sb -in .m_outp.f -side left -expand 1 -fill both
grid .m_outp.f
bind .m_outp.lb <ButtonPress-1> {exit}
}
 
Hello,

I just got it:

foreach i $cliste { .m.outp.lb insert end $i }


Thanks for reading anyway
Stefan
 
You can also do it when you set up the listbox. You have:
listbox .m_outp.lb -selectmode single -height 10.

Instead use:
listbox .m_outp.lb -selectmode single -height 10 [red]-listvariable cliste[/red].



_________________
Bob Rashkin
rrashkin@csc.com
 
Hello Bong,

thanks for your replay.
I tried it many times with the options you described because it seemed so logically to me. But I never got the list in the window. Is there another thing I could miss in this area ?
 
I've never had any problem with this option. It may be that your list is in a different scope than your listbox? Is the list, by any chance, defined in a proc?

_________________
Bob Rashkin
rrashkin@csc.com
 
Hello Bong,

yes you are right, this list is created in a proc. Does this have an effect displaying the list with a listbox ?


Regards
Stefan
 
I don't know for sure but I've seen things like this before. Try making the list a "global" variable and don't pass it in.

_________________
Bob Rashkin
rrashkin@csc.com
 
i've just learned you can't assign a local variable to a listbox which is global available

you have 3 options:
1. use a global variable and unset it after use
2. use a namespace
3. fill up the listbox with insert

*****************************************************
1.
proc get_dirs {dir} {
set lDirs {}

foreach i [glob /* [exec ls -a $dir]] {
lappend lDirs $i
}
return $lDirs
}

proc make {} {
set ::lDirs [get_dirs "${::basedir}"]

listbox .lstFoundry -relief sunken
-listvariable ::lDirs

unset ::lDirs
}

set ::basedir "/"
make

*****************************************************

3.
proc fill_listbox {box dir} {
if {![file exists $dir]} {
puts "directory $dir does not exist"
return -1
}

foreach i [glob /* [exec ls -a $dir]] {
eval [$box insert end $i]
}
}

proc make {} {
fill_listbox ".lstFoundry" "${::basedir}"

listbox .lstFoundry -relief sunken
-listvariable ::lDirs
}

set ::basedir "/"
make


Note: this is a summary of the thread at:
 
sorry, but this line has to be corrected:

foreach i [glob /* [exec ls -a $dir]] {
#...
}
TO

foreach i [exec ls -a $dir] {
if {[file exists "$dir/$i"]} {
eval [$box insert end $i]
}

#...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top