我创建了 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 在这里编译的代码教程的扩展,我认为有点过时了。