Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to bind mouse wheel with the scroll bar on scrollable window?

980 views
Skip to first unread message

wn0...@gmail.com

unread,
Aug 31, 2012, 2:43:44 AM8/31/12
to
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?

George Petasis

unread,
Aug 31, 2012, 3:52:11 AM8/31/12
to
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

Andy

unread,
Aug 31, 2012, 5:18:21 AM8/31/12
to
在 2012年8月31日星期五UTC+8下午3时52分17秒,George Petasis写道:
> Στις 31/8/2012 09:43, ο/η wn0...@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.)

Georgios Petasis

unread,
Aug 31, 2012, 5:53:48 AM8/31/12
to
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 from 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

Harald Oehlmann

unread,
Aug 31, 2012, 7:26:06 AM8/31/12
to
On Aug 31, 11:54 am, Georgios Petasis <peta...@iit.demokritos.gr>
wrote:
>
> 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.

Thank you George, that is a good straitforward approach.

Other approaches try to find a scrolling widget in all decending
widgets.

Tk8.6 has such a solution.

There is a button on wiki.tcl.tk/bwidget about this issue.

I tried the proposal of Koen for 8.5 but got some errors with some
widgets.
But I did not try long enopugh...

Uwe Klein

unread,
Aug 31, 2012, 7:24:57 AM8/31/12
to
Georgios Petasis wrote:
> You have to call this for all widgets you have put in the frame.
>
> George

little test/example ( my mousewheel is on b4/b5, ancient):

#!/usr/bin/wish

toplevel .t -bg green -width 100 -height 100
frame .t.f -bg yellow ; pack .t.f -expand 1 -fill both
button .t.f.b -text hallo -command exit ; pack .t.f.b

bind .t.f <MouseWheel> {puts stderr MouseWheel}
bind .t.f <1> {puts stderr B1}
bind .t.f <2> {puts stderr B2}
bind .t.f <3> {puts stderr B3}
bind .t.f <4> {puts stderr B4}
bind .t.f <5> {puts stderr "B5 x:%x y:%y" }

bind .t.f.b <4> {puts stderr BB4}
bind .t.f.b <5> {puts stderr "BB5-x%x y:%y" ; event generate .t.f <5> -x %x -y %y ; puts stderr -BB5}

for mousewheel:
bind .t.f.b <MouseWheel> {i
puts stderr "MW: x%x y:%y D:%D" ;
event generate .t.f <MouseWheel> -x %x -y %y -delta %D
}

Andy

unread,
Sep 5, 2012, 6:51:17 AM9/5/12
to
在 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, ο/η wn0...@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 from 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"
...
-------------------------------------------------------

Georgios Petasis

unread,
Sep 9, 2012, 12:43:19 PM9/9/12
to Andy
sw should be a tklib scrolledwidget, and win a widget inside the
scrolled area.

George

Andy

unread,
Sep 10, 2012, 10:38:04 PM9/10/12
to Andy
在 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?

Andy

unread,
Sep 11, 2012, 4:45:20 AM9/11/12
to Andy
在 2012年9月11日星期二UTC+8上午10时38分04秒,Andy写道:
> 在 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?

Interesting things. After packing my tcl script to .exe file, it works even if I didn't use ttk widgets.
0 new messages