0

我创建了 4 个列表框和 4 个它们绑定的滚动条。但是滚动条没有按预期工作:它们在滚动列表框时相互干扰,最后一个滚动不起作用。tkyview我在and中找不到任何其他选项tkset来解决此问题。你觉得这里有什么问题?

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)
}

这段代码是 James Wettenhall 在这里编译的代码教程的扩展,我认为有点过时了。

4

1 回答 1

1

当您创建上面的所有滚动条时,您将命令设置tkyviewt.d列表框,因此您已经告诉所有 4 个滚动条移动同一个框。如果您修正错字并让最后 3 个tkyview函数调用最后 3 个列表框对象,那么它就可以工作。

于 2012-11-01T15:59:52.007 回答