ttkmenu.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # ttkmenu.tcl --
  2. #
  3. # This demonstration script creates a toplevel window containing several Ttk
  4. # menubutton widgets.
  5. if {![info exists widgetDemo]} {
  6. error "This script should be run from the \"widget\" demo."
  7. }
  8. package require Tk
  9. package require Ttk
  10. set w .ttkmenu
  11. catch {destroy $w}
  12. toplevel $w
  13. wm title $w "Ttk Menu Buttons"
  14. wm iconname $w "ttkmenu"
  15. positionWindow $w
  16. ttk::label $w.msg -font $font -wraplength 4i -justify left -text "Ttk is the new Tk themed widget set, and one widget that is available in themed form is the menubutton. Below are some themed menu buttons that allow you to pick the current theme in use. Notice how picking a theme changes the way that the menu buttons themselves look, and that the central menu button is styled differently (in a way that is normally suitable for toolbars). However, there are no themed menus; the standard Tk menus were judged to have a sufficiently good look-and-feel on all platforms, especially as they are implemented as native controls in many places."
  17. pack $w.msg [ttk::separator $w.msgSep] -side top -fill x
  18. ## See Code / Dismiss
  19. pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
  20. ttk::menubutton $w.m1 -menu $w.m1.menu -text "Select a theme" -direction above
  21. ttk::menubutton $w.m2 -menu $w.m1.menu -text "Select a theme" -direction left
  22. ttk::menubutton $w.m3 -menu $w.m1.menu -text "Select a theme" -direction right
  23. ttk::menubutton $w.m4 -menu $w.m1.menu -text "Select a theme" \
  24. -direction flush -style TMenubutton.Toolbutton
  25. ttk::menubutton $w.m5 -menu $w.m1.menu -text "Select a theme" -direction below
  26. menu $w.m1.menu -tearoff 0
  27. menu $w.m2.menu -tearoff 0
  28. menu $w.m3.menu -tearoff 0
  29. menu $w.m4.menu -tearoff 0
  30. menu $w.m5.menu -tearoff 0
  31. foreach theme [ttk::themes] {
  32. $w.m1.menu add command -label $theme -command [list ttk::setTheme $theme]
  33. $w.m2.menu add command -label $theme -command [list ttk::setTheme $theme]
  34. $w.m3.menu add command -label $theme -command [list ttk::setTheme $theme]
  35. $w.m4.menu add command -label $theme -command [list ttk::setTheme $theme]
  36. $w.m5.menu add command -label $theme -command [list ttk::setTheme $theme]
  37. }
  38. pack [ttk::frame $w.f] -fill x
  39. pack [ttk::frame $w.f1] -fill both -expand yes
  40. lower $w.f
  41. grid anchor $w.f center
  42. grid x $w.m1 x -in $w.f -padx 3 -pady 2
  43. grid $w.m2 $w.m4 $w.m3 -in $w.f -padx 3 -pady 2
  44. grid x $w.m5 x -in $w.f -padx 3 -pady 2