Updated 2011-07-19 12:26:46 by RLE

Richard Suchenwirth 2003-08-07 - Buttons and other UI items that are disabled, are drawn on Windows in a style called "Unavailable appearance", which looks like the font had a sunken relief. Here is a workaround to have this effect in Tk too: We first create a label with a white text, save this using Img to a photo image, and do a bit of image processing to add gray pixels as left-top neighbors to white pixels:


 package require Img
 pack [label .x -text Unavailable -fg white]
 after idle
 set im [image create photo -format window -data .x]
 set w [image width $im]
 set h [image height $im]
 for {set y 1} {$y<$h} {incr y} {
   for {set x 1} {$x<$w} {incr x} {
      if {[$im get $x $y]=={255 255 255}} {
         $im put gray40 -to [expr {$x-1}] [expr {$y-1}]
      }
   }
 }
 .x config -image $im

However, this does not reflect the -state of the button - more code is needed for that functionality.

Come to think, this might be done in Tk core at the place where -disabledforeground is displayed, by rendering the text in white before, shifted by 1 pixel each in x,y directions; conditionally for Windows, or: for all platforms?

PT Tile does this for widgets with a disabled state and for themes that require this sort of effect (eg: winnative and xpnative - also alt IIRC)