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

如何将滚动条添加到tcl框架,tcl,tk,Tcl,Tk,我在一个框架上创建一个单选按钮列表,列表最终会变得巨大,用户很难选择项目。 我是否可以在这个框架中添加滚动条? 我尝试添加列表框,但没有帮助 这是我的密码 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 se

我在一个框架上创建一个单选按钮列表,列表最终会变得巨大,用户很难选择项目。 我是否可以在这个框架中添加滚动条? 我尝试添加列表框,但没有帮助

这是我的密码

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

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

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

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


但是,您可以将框架放在画布中(通过“小部件”画布项目类型),画布可以滚动,只要您告诉画布滚动区域是什么。您需要确保框架及其内容是画布的子对象,以便正确地剪裁它们。

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


但是,您可以将框架放在画布中(通过“小部件”画布项目类型),画布可以滚动,只要您告诉画布滚动区域是什么。您需要确保框架及其内容是画布的子对象,以便正确地剪裁它们。

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

#!/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
#/usr/bin/env-wish
帧,帧
#使用滚动条创建画布
canvas.frAlles.c-宽度400-高度200-xscrollcommand“.frAlles.xscroll集合”-yscrollcommand“.frAlles.yscroll集合”
ttk::scrollbar.frAlles.xscroll-定向水平-命令“.frAlles.cxview”
ttk::scrollbar.frAlles.yscroll-command“.frAlles.cyView”
pack.frAlles.xscroll-侧面底部-填充x
pack.frAlles.yscroll-右侧-填充y
pack.frAlles.c-扩展是-填充两侧顶部
#使用小部件创建框架
ttk::frame.frAlles.c.frWidgets-边框宽度1-浮雕实心-宽度340-高度700

对于{set i 0}{$i您可以将画布与滚动条结合使用,然后将小部件放在画布上。例如:

#!/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
!/usr/bin/env-wish
帧,帧
#使用滚动条创建画布
canvas.frAlles.c-宽度400-高度200-xscrollcommand“.frAlles.xscroll集合”-yscrollcommand“.frAlles.yscroll集合”
ttk::scrollbar.frAlles.xscroll-定向水平-命令“.frAlles.cxview”
ttk::scrollbar.frAlles.yscroll-command“.frAlles.cyView”
pack.frAlles.xscroll-侧面底部-填充x
pack.frAlles.yscroll-右侧-填充y
pack.frAlles.c-扩展是-填充两侧顶部
#使用小部件创建框架
ttk::frame.frAlles.c.frWidgets-边框宽度1-浮雕实心-宽度340-高度700

对于{set i0}{$i好的,好的,但是可以缩小radiobutton的大小以适应相同大小的框架吗?有没有关于radiobutton大小的选项?@DanishSheikh:你看过文档了吗?是的,有,但不要这样做。试着使用列表框,就像Mario建议的那样。好的,那么radiobutton的大小可以缩小到acc吗Omodate在相同大小的框架中?是否有选择单选按钮大小的选项?@DanishSheikh:您看过文档了吗?是的,有,但不要这样做。尝试使用列表框,就像Mario建议的那样。在这种情况下,a比单选按钮有用得多。在这种情况下,a比单选按钮有用得多。