Posted to tcl by patthoyts at Sat Jul 29 18:29:50 GMT 2006view raw

  1. # This script demonstrates how to create a non-themed button using the Tile
  2. # Tk extension. In this case we regain control of the button background
  3. # colour by loosing the XP themeing. However we retain the current theme
  4. # settings for all the other elements - this meand the focus ring will
  5. # look right and the text will use the right font and the correct
  6. # shading for disabled buttons.
  7. #
  8. # Note that we are defining this for the current theme. On Windows XP
  9. # tile defaults to xpnative and so this override is in effect in this theme.
  10. # If you switch to another theme - eg: plastik you will get a plastik themed
  11. # button.
  12.  
  13. package require Tk
  14. package require tile
  15.  
  16. # -------------------------------------------------------------------------
  17.  
  18. # We import the border element from the default theme.
  19. style element create plain.border from default
  20.  
  21. # Create a new layout style for our custom button which uses default
  22. # elements and our imported element for the border.
  23.  
  24. style layout Plain.TButton {
  25. background -children {
  26. plain.border -children {
  27. focus -children {
  28. padding -children {
  29. label -sticky news
  30. }
  31. }
  32. }
  33. }
  34. }
  35.  
  36. # Configure our custom style so it looks like a button
  37. style configure Plain.TButton -relief raised -shiftrelief 1
  38.  
  39. # If we want to fix the colour to something for this style then:
  40. style configure Plain.TButton -background LightSteelBlue
  41.  
  42. # Configure the event map so that it depresses when clicked.
  43. style map Plain.TButton -relief {
  44. {!disabled pressed} sunken
  45. }
  46.  
  47. # -------------------------------------------------------------------------
  48. # Sample application.
  49.  
  50. ttk::button .bn -text Normal
  51. ttk::button .bp -text Plain -style Plain.TButton
  52. ttk::button .bx -text Exit -underline 1 -command exit
  53. grid .bn .bp -padx 2 -pady 2
  54. grid .bx - -pady 2
  55. bind . <Control-F2> {console show}
  56.