Button Focus Highlighting Under Windows

Jeff Epler jepler at unpythonic.net
Mon Dec 2 12:27:31 EST 2002


On Sat, Nov 30, 2002 at 06:38:02PM -0800, HardYards wrote:
> Am I going silly or don't buttons have a highlight state when running
> under windows?
> 
> I want to build a toolbar with the behaviour that when the mouse is
> over a button it is highlighted.
> 
> Thinking it was me I tried the following example from the web, and it
> doesn't work either.

On Windows, the "highlightbackground" of a button is the same as the
normal color.  This is different from Unix (and possibly different from
Macintosh)

[In Tk running on Windows NT]
% .b cget -highlightbackground
SystemButtonFace
% .b cget -background
SystemButtonFace

You could explicitly configure your button to have a different
highlightbackground when creating it.  For instance:
    self.button1.configure(highlightbackground="#30ff30")

'highlightcolor' and 'highlightthickness' refer to the appearance of the
(normally) thin black line drawn around the outside of the widget with
keyboard focus.  These may behave differently on NT than on Unix, since
there a focused button is drawn with a dotted rectangle inside the relief,
not a solid rectangle outside the relief as on Unix/Motif.

Tk seems to give the worst of all worlds:  It doesn't perfectly imitate
the appearance of any platform, but it imitates just enough that you
have to take extra steps to make things look approximately the same on
different platforms.

Jeff




More information about the Python-list mailing list