2016-10-10 96 views
0

我正在創建一個框架上的單選按鈕列表,該列表最終變得非常龐大,用戶難以選擇項目。 無論如何,我可以添加一個滾動條到這個框架? 我嘗試添加列表框,但沒有幫助。如何向tcl框架添加滾動條

這是我的代碼。

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

在這種情況下[列表框(https://www.tcl.tk/man/tcl8.4/TkCmd/listbox.htm)比單選按鈕許多有益的。 –

回答

0

你不能那樣做。只有具有滾動命令選項的小部件(-xscrollcommand,-yscrollcommand)和xview/yview小部件命令才能滾動。

+0

好的,但是,然後可以減小單選按鈕的大小以適應相同尺寸的框架?是否有任何選擇的單選按鈕尺寸? –

+0

@DanishSheikh:你看過文檔嗎?是的,有,但不這樣做。請嘗試使用列表框,而不是像Mario建議的那樣。 –

1

只有實現Tk的滾動協議的小部件可以與滾動條關聯;框架不是這樣一個小部件。

但是,您可以將您的框架放置在畫布內(通過「小部件」畫布項目類型),並且畫布可滾動,只要您告訴畫布滾動區域是什麼。您需要確保框架及其內容是畫布的子項,以便裁剪它們以正確工作。

1

您可以使用與滾動條相結合的畫布,而不是將小部件放在畫布上。例如:

#!/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