[ tktoolkit-Bugs-2010011 ] Ttk buttons keep focus when clicked

View: New views
1 Messages — Rating Filter:   Alert me  

[ tktoolkit-Bugs-2010011 ] Ttk buttons keep focus when clicked

by SourceForge.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bugs item #2010011, was opened at 2008-07-03 12:47
Message generated for change (Comment added) made by jenglish
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112997&aid=2010011&group_id=12997

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: 88. Themed Tk
Group: None
Status: Closed
Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Talvo (talvo)
Assigned to: Joe English (jenglish)
Summary: Ttk buttons keep focus when clicked

Initial Comment:
When you click a regular Tk button, it won't take the focus from whichever widget currently has it (though you can still specifically give it focus via the keyboard).

Ttk buttons (Win XP SP3, xpnative theme but with Windows configured to use the classic look) take focus when clicked, though. Brief example:

pack [frame .top]
pack [frame .btm]
pack [button .top.btn -text "Tk" -command "puts Tk"]
pack [ttk::button .top.btn2 -text "Ttk" -command "puts Ttk"]
pack [text .btm.txt -width 10 -height 3]
focus -force .btm.txt

If you then click the Tk button, focus stays in the text widget. When you click the Ttk button, though, it retains focus.

The issue is even worse when you combine several Tk/Ttk buttons; in the example above, click the 'Tk' button again. The Ttk button still retains focus afterwards, so even though it wasn't explicitly given focus via the keyboard (and although another button has been activated via the mouse), the Ttk button still remains active and can be invoked via the spacebar.

----------------------------------------------------------------------

>Comment By: Joe English (jenglish)
Date: 2008-07-04 11:22

Message:
Logged In: YES
user_id=68433
Originator: NO

Since toolbar buttons typically do not participate in keyboard traversal
either, you might consider setting '-takefocus 0' instead.  If you use a
consistent naming or class convention (e.g., all toolbar frames have
'-class Toolbar') you can even use the option database to make this happen
automatically:

    option add *Toolbar*TButton.takeFocus 0

----------------------------------------------------------------------

Comment By: Talvo (talvo)
Date: 2008-07-04 11:14

Message:
Logged In: YES
user_id=1719772
Originator: YES

Thanks for the reply. I'd had the same experience as Bryan mentioned in
the link you gave - clicking a toolbar button in Internet Explorer/Outlook
Express/Wordpad/etc doesn't move the focus, so I assumed it wasn't supposed
to happen. Should've known better than to trust Microsoft to follow their
own specs.

I think I'll probably go with something like
bind TButton <1> {%W instate !disabled { %W state pressed } }

as I don't want to disable click-to-focus for radiobuttons or other
widgets, just standard buttons.

Thanks for your help.

----------------------------------------------------------------------

Comment By: Joe English (jenglish)
Date: 2008-07-04 10:32

Message:
Logged In: YES
user_id=68433
Originator: NO

This is an intentional difference in [ttk::button]s from core [button]s,
since click-to-focus is the default behavior on more platforms than not
(including Windows XP).

To disable this for a single widget, use [$b configure -takefocus 0].
(Note that this will also disable keyboard traversal).  To disable this for
the entire application, you can stub out proc ttk::clickToFocus:  

proc ttk::clickToFocus {args} { ;# do nothing }

See also the discussion on tktable-tile-dev from May 2006, Subject:
"setting focus on button clicks: on purpose?"

http://sourceforge.net/mailarchive/forum.php?forum_name=tktable-tile-dev&max_rows=100&style=threaded&viewmonth=200605

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112997&aid=2010011&group_id=12997

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Tcl-Bugs mailing list
Tcl-Bugs@...
https://lists.sourceforge.net/lists/listinfo/tcl-bugs