Ebrahim Jahanshiri
Ebrahim Jahanshiri

Reputation: 93

Multiple listboxs and scrollbars tcl/tk and R

I have created 4 listboxes and 4 scrollbars to which they bind. However the scrollbars don't work as expected: they interfere with each other in scrolling listboxes and the last scroll does not work. I couldn't find any other option in the tkyview and tkset to fix this problem. What do you think is wrong here?

require(tcltk)
tt <- tktoplevel()

#Scrollbars
scr.d <- tkscrollbar(tt, repeatinterval=4,command=function(...) tkyview(t.d,...))
scr.m <- tkscrollbar(tt, repeatinterval=4,command=function(...) tkyview(t.d,...))
scr.s <- tkscrollbar(tt, repeatinterval=4,command=function(...) tkyview(t.d,...))
scr.a <- tkscrollbar(tt, repeatinterval=4,command=function(...) tkyview(t.d,...))

#Listboxes
t.d <- tklistbox(tt, selectmode="browse",yscrollcommand=function(...) tkset(scr.d,...), width=20,background="white", exportselection=0)
t.m <- tklistbox(tt, selectmode="Single",
                 yscrollcommand=function(...) tkset(scr.m,...), width=20, background="white", exportselection=0)
t.s <- tklistbox(tt,selectmode="Single",
                 yscrollcommand=function(...) tkset(scr.s,...), width=30, background="white", exportselection=0)
t.a <- tklistbox(tt,selectmode="Single",
                 yscrollcommand=function(...) tkset(scr.a,...), width=35, background="white", exportselection=0)

#Place them on the window
tkgrid(tklabel(tt,text="Select subject property:"))
tkgrid(tklabel(tt,text=""))
tkgrid(t.d, scr.d,t.m, scr.m, t.s, scr.s, t.a, scr.a)

tkgrid.configure(scr.d,rowspan=4,sticky="nsw")
tkgrid.configure(scr.m,rowspan=4,sticky="nsw")
tkgrid.configure(scr.s,rowspan=4,sticky="nsw")
tkgrid.configure(scr.a,rowspan=4,sticky="nsw")

#Filling up the listboxes
for (i in 1:100)
{
  tkinsert(t.d, "end", i)
}

for (i in letters)
{
  tkinsert(t.m, "end", i)
}

for (i in rnorm(100))
{
  tkinsert(t.s, "end", i)
}

for (i in letters)
{
  tkinsert(t.a, "end", i)
}

This code is the extension of the code tutorial compiles by James Wettenhall in here and I think is a little bit outdated.

Upvotes: 0

Views: 1023

Answers (1)

Greg Snow
Greg Snow

Reputation: 49640

When you create all the scrollbars above you set the command to tkyview of the t.d list box, so you have told all 4 scrollbars to move the same box. If you fix the typo and have the last 3 tkyview functions call the last 3 listbox objects then it works.

Upvotes: 1

Related Questions