ttkmenu.tcl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. set w .ttkmenu
  10. catch {destroy $w}
  11. toplevel $w
  12. wm title $w "Ttk Menu Buttons"
  13. wm iconname $w "ttkmenu"
  14. positionWindow $w
  15. 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."
  16. pack $w.msg [ttk::separator $w.msgSep] -side top -fill x
  17. ## See Code / Dismiss
  18. pack [addSeeDismiss $w.seeDismiss $w] -side bottom -fill x
  19. ttk::menubutton $w.m1 -menu $w.m1.menu -text "Select a theme" -direction above
  20. ttk::menubutton $w.m2 -menu $w.m1.menu -text "Select a theme" -direction left
  21. ttk::menubutton $w.m3 -menu $w.m1.menu -text "Select a theme" -direction right
  22. ttk::menubutton $w.m4 -menu $w.m1.menu -text "Select a theme" \
  23. -direction flush -style TMenubutton.Toolbutton
  24. ttk::menubutton $w.m5 -menu $w.m1.menu -text "Select a theme" -direction below
  25. menu $w.m1.menu -tearoff 0
  26. menu $w.m2.menu -tearoff 0
  27. menu $w.m3.menu -tearoff 0
  28. menu $w.m4.menu -tearoff 0
  29. menu $w.m5.menu -tearoff 0
  30. foreach theme [ttk::themes] {
  31. $w.m1.menu add command -label $theme -command [list ttk::setTheme $theme]
  32. $w.m2.menu add command -label $theme -command [list ttk::setTheme $theme]
  33. $w.m3.menu add command -label $theme -command [list ttk::setTheme $theme]
  34. $w.m4.menu add command -label $theme -command [list ttk::setTheme $theme]
  35. $w.m5.menu add command -label $theme -command [list ttk::setTheme $theme]
  36. }
  37. pack [ttk::frame $w.f] -fill x
  38. pack [ttk::frame $w.f1] -fill both -expand yes
  39. lower $w.f
  40. grid anchor $w.f center
  41. grid x $w.m1 x -in $w.f -padx 3 -pady 2
  42. grid $w.m2 $w.m4 $w.m3 -in $w.f -padx 3 -pady 2
  43. grid x $w.m5 x -in $w.f -padx 3 -pady 2