如何将滚动条添加到tcl框架

时间:2016-10-10 10:48:32

标签: tcl tk

我正在创建一个框架上的radiobuttons列表,该列表最终变得庞大,用户难以选择项目。 无论如何我可以在此框架中添加滚动条吗? 我尝试添加列表框,但没有帮助。

这是我的代码。

frame .top.d.b -width 100 -height 20 -borderwidth 2 -relief raised
label .top.d.b.l1 -font fontTEMP_varwidth -text "Comparision Libraries" -anchor center -padx 2 -pady 4
set whu .top.d.b
grid .top.d.b -row 7 -column 2 -sticky nsew
grid .top.d.b.l1 -row 1 -column 2
set w 0
foreach elem $mylist {
radiobutton .top.d.b.$w -text $elem -command [list selectlib $elem $w] -value $elem.abc -padx 2 -pady 2
grid .top.d.b.$w -row $a -column $r -sticky w
incr a
incr w
}
} else {
puts "STD_CELLS_LIBPATH not found\n"
}
}

3 个答案:

答案 0 :(得分:2)

您可以将画布与滚动条结合使用,而不是将小部件放在画布上。例如:

#!/usr/bin/env wish

ttk::frame .frAlles

# create canvas with scrollbars
canvas .frAlles.c -width 400 -height 200 -xscrollcommand ".frAlles.xscroll set" -yscrollcommand ".frAlles.yscroll set"
ttk::scrollbar .frAlles.xscroll -orient horizontal -command ".frAlles.c xview"
ttk::scrollbar .frAlles.yscroll -command ".frAlles.c yview"
pack .frAlles.xscroll -side bottom -fill x
pack .frAlles.yscroll -side right -fill y
pack .frAlles.c -expand yes -fill both -side top

# create frame with widgets
ttk::frame .frAlles.c.frWidgets -borderwidth 1 -relief solid -width 340 -height 700

for {set i 0} {$i <=20} {incr i} {
  ttk::label .frAlles.c.frWidgets.lb$i -text "Label $i:"
  ttk::entry .frAlles.c.frWidgets.en$i
  ttk::button .frAlles.c.frWidgets.bt$i -text "Button $i" -command exit
  grid .frAlles.c.frWidgets.lb$i -padx 2 -pady 2 -row $i -column 0
  grid .frAlles.c.frWidgets.en$i -padx 2 -pady 2 -row $i -column 1
  grid .frAlles.c.frWidgets.bt$i -padx 2 -pady 2 -row $i -column 2 
}

# create frame with buttons
ttk::frame .frAlles.c.frButtons -borderwidth 1 -relief solid -width 340 -height 40
ttk::button .frAlles.c.frButtons.btOK -text "OK" -command exit
ttk::button .frAlles.c.frButtons.btAbbruch -text "Abbruch" -command exit
pack .frAlles.c.frButtons.btOK -padx 2 -pady 2 -side left
pack .frAlles.c.frButtons.btAbbruch -padx 2 -pady 2 -side left

# place widgets and buttons
.frAlles.c create window 0 0 -anchor nw -window .frAlles.c.frWidgets 
.frAlles.c create window 200 650 -anchor c -window .frAlles.c.frButtons 

# determine the scrollregion
.frAlles.c configure -scrollregion [.frAlles.c bbox all]

# show the canvas
pack .frAlles -expand yes -fill both -side top

答案 1 :(得分:1)

只有实现Tk滚动协议的小部件才能与滚动条关联;帧不是这样的小部件。

但是,您可以将画面放在画布中(通过“小部件”画布项类型),并且画布 可滚动,前提是您告诉画布滚动区域是什么。您需要确保框架及其内容是画布的子项,以便剪切它们才能正常工作。

答案 2 :(得分:0)

你不能这样做。只能滚动具有scrollcommand选项(-xscrollcommand,-yscrollcommand)和xview / yview窗口小部件命令的窗口小部件。