在 2012年9月10日星期一UTC+8上午12时43分21秒,Georgios Petasis写道:
> Στις 5/9/2012 13:51, ο/η Andy έγραψε: > 在 2012年8月31日星期五UTC+8下午5时54分01秒,Georgios Petasis写道: >> Στις 31/8/2012 12:18, ο/η Andy έγραψε: > 在 2012年8月31日星期五UTC+8下午3时52分17秒,George Petasis写道: >> Στις 31/8/2012 09:43, ο/η
wn...@gmail.com έγραψε: > package require BWidget > > set sw [ ScrolledWindow .sw ] > pack $sw -side top -fill both -expand true > > set sf [ ScrollableFrame .sf ] > $sw setwidget $sf > set uf [ $sf getframe ] > > If you create many widgets on scrollable frame, scroll bar appears, but mouse wheel cannot control the scroll bar. > > How to bind mouse wheel with the scroll bar? > I suppose that the mouse wheel is already binded to the scrollable frame. What stops it from scrolling, is the widgets. You have to add the proper bindings to all widgets inside the scrollbar. George > > But I only created several checkboxes on that frame, no scrollable widgets( list, text etc.) > Yes, but when the mouse is over a checkbox, the checkbox receives the mouse wheel events, not the scrollable frame. This a piece of code fr om an app of mine: method addScrollBindings {sw win} { bind $win <MouseWheel> \ "$sw yview scroll \[expr {- (%D / 120) * 4}\] units" bind $win <4> "$sw yview scroll -5 units" bind $win <5> "$sw yview scroll 5 units" };# addScrollBindings sw is a scrollable widget from tklib, but it may work for scrollable frames. You have to call this for all widgets you have put in the frame. George > > Thank you George, but I'm not quite clear about the usage of this proc. > Could you give me an example? > > When I try to invoke this proc, I got an error. > ------------------------------------------------------- > invalid command name ".sw yview scroll [expr {-(%D/120)*4}] units" > while executing > ""$sw yview scroll \[expr {-(%D/120)*4}\] units"" > (procedure "addScrollBindings" line 3) > invoked from within > "addScrollBindings $sw $top" > ... > ------------------------------------------------------- > sw should be a tklib scrolledwidget, and win a widget inside the scrolled area. George
Thanks, George. It works, this is my code.
package require BWidget
proc addScrollBindings {sw win} {
bind $win <MouseWheel> "$sw yview scroll \[ expr {- (%D / 120) * 4}\] units"
bind $win <4> "$sw yview scroll -5 units"
bind $win <5> "$sw yview scroll 5 units"
};
set sw [ ScrolledWindow .sw ]
pack $sw -side top -fill both -expand true
set sf [ ScrollableFrame .sf ]
$sw setwidget $sf
set uf [ $sf getframe ]
foreach val {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17} {
ttk::checkbutton $uf.cb$val -text hello$val
pack $uf.cb$val -side top
}
foreach w [ winfo children $uf ] {
addScrollBindings .sf $w
}
But if I replace ttk::checkbutton with checkbutton, it doesn't work. Why?