3 # This demonstration script creates a toolbar that can be torn off.
5 if {![info exists widgetDemo
]} {
6 error "This script should be run from the \"widget\" demo."
15 wm title
$w "Toolbar Demonstration"
16 wm iconname
$w "toolbar"
19 if {[tk windowingsystem
] ne
"aqua"} {
20 ttk
::label $w.msg
-wraplength 4i
-text "This is a demonstration of how to do\
21 a toolbar that is styled correctly and which can be torn off. The\
22 buttons are configured to be \u201Ctoolbar style\u201D buttons by\
23 telling them that they are to use the Toolbutton style. At the left\
24 end of the toolbar is a simple marker that the cursor changes to a\
25 movement icon over; drag that away from the toolbar to tear off the\
26 whole toolbar into a separate toplevel widget. When the dragged-off\
27 toolbar is no longer needed, just close it like any normal toplevel\
28 and it will reattach to the window it was torn off from."
30 ttk
::label $w.msg
-wraplength 4i
-text "This is a demonstration of how to do\
31 a toolbar that is styled correctly. The buttons are configured to\
32 be \u201Ctoolbar style\u201D buttons by telling them that they are\
33 to use the Toolbutton style."
36 ## Set up the toolbar hull
37 set t
[frame $w.toolbar
] ;# Must be a frame!
39 ttk
::frame $t.tearoff
-cursor fleur
40 if {[tk windowingsystem
] ne
"aqua"} {
41 ttk
::separator $t.tearoff.to
-orient vertical
42 ttk
::separator $t.tearoff.to2
-orient vertical
43 pack $t.tearoff.to
-fill y
-expand 1 -padx 2 -side left
44 pack $t.tearoff.to2
-fill y
-expand 1 -side left
46 ttk
::frame $t.contents
47 grid $t.tearoff
$t.contents
-sticky nsew
48 grid columnconfigure
$t $t.contents
-weight 1
49 grid columnconfigure
$t.contents
1000 -weight 1
51 if {[tk windowingsystem
] ne
"aqua"} {
52 ## Bindings so that the toolbar can be torn off and reattached
53 bind $t.tearoff
<B1-Motion
> [list tearoff
$t %X
%Y
]
54 bind $t.tearoff.to
<B1-Motion
> [list tearoff
$t %X
%Y
]
55 bind $t.tearoff.to2
<B1-Motion
> [list tearoff
$t %X
%Y
]
56 proc tearoff
{w x y
} {
57 if {[string match
$w* [winfo containing
$x $y]]} {
61 grid remove
$w.tearoff
63 wm protocol
$w WM_DELETE_WINDOW
[list untearoff
$w]
73 ttk
::button $t.
button -text "Button" -style Toolbutton
-command [list \
74 $w.txt insert end
"Button Pressed\n"]
75 ttk
::checkbutton $t.check
-text "Check" -variable check
-style Toolbutton
\
76 -command [concat [list $w.txt insert end
] {"check is $check\n"}]
77 ttk
::menubutton $t.
menu -text "Menu" -menu $t.
menu.m
78 ttk
::combobox $t.combo
-value [lsort [font families
]] -state readonly
80 $t.
menu.m add command
-label "Just" -command [list $w.txt insert end Just
\n]
81 $t.
menu.m add command
-label "An" -command [list $w.txt insert end An
\n]
82 $t.
menu.m add command
-label "Example" \
83 -command [list $w.txt insert end Example
\n]
84 bind $t.combo
<<ComboboxSelected
>> [list changeFont
$w.txt
$t.combo
]
85 proc changeFont
{txt combo
} {
86 $txt configure
-font [list [$combo get
] 10]
89 ## Some content for the rest of the toplevel
90 text $w.txt
-width 40 -height 10
91 interp alias
{} doInsert
{} $w.txt insert end
;# Make bindings easy to write
94 grid $t.
button $t.check
$t.
menu $t.combo
-in $t.contents
-padx 2 -sticky ns
96 grid $w.sep
-sticky ew
97 grid $w.msg
-sticky ew
98 grid $w.txt
-sticky nsew
99 grid rowconfigure
$w $w.txt
-weight 1
100 grid columnconfigure
$w $w.txt
-weight 1
102 ## See Code / Dismiss buttons
103 set btns
[addSeeDismiss
$w.buttons
$w]
104 grid $btns -sticky ew