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

Disappearing class binding when using ttk::button -command

11 views
Skip to first unread message

dwto...@googlemail.com

unread,
Feb 21, 2008, 11:08:11 AM2/21/08
to
Hi all,

I am having a problem with class bindings when using tk 8.5.0.
Consider the following, which is a very distilled version of my
application code. Note that the button is from ttk.

bind Dwt <Control-p> {puts "^p in %W"}

toplevel .w -class Dwt
frame .w.f1 -width 100 -height 100
ttk::button .w.f2 -text "Press me!" -command {grid remove .w.f2}
grid .w.f1
grid .w.f2

If I press ^p in the window, the binding commands puts the message to
the screen as expected. If I remove the button from the window
manually, using `grid remove .w.f2', the binding still works. If I
press the button to invoke the command to remove the button from the
display, then the class binding no longer works in the remaining
frame. If I use a plain tk button, instead of a ttk button, then the
above code fragment will work.

Am I doing something fundamentally wrong here, or is this a bug in the
way that ttk::button commands are invoked?

thanks,

dan.

Bryan Oakley

unread,
Feb 21, 2008, 12:06:38 PM2/21/08
to

I think what is happening is that when you click on a ttk button it
takes the focus (something I think is wrong, but that's what it does).
Since it has the keyboard focus, and there's no control-p binding on
that widget, nothing happens.

Alter your button to look like the following and your control-p binding
will work after pressing the button:

ttk::button .w.f2 -text "Press me!" -command {
grid remove .w.f2

focus .w
}

Alternatively, you can set -takefocus to false on the widget, but then
keyboard traversal won't work.

I think, though, you misunderstand class bindings and bindtags. If you
want to create a binding that is universal for a given toplevel you
can't use class bindings because other widgets don't inherit those
bindings. If the focus moves away from .w the binding won't fire.

You might want to see how your app behaves when you set the binding to
.w instead of Dtw since that will make sure that all widgets that are in
.w will inherit the binding.


--
Bryan Oakley
http://www.tclscripting.com

0 new messages