1Toplevel(n) [incr Tk] Toplevel(n)
2
3
4
5______________________________________________________________________________
6
8 Toplevel - base class for mega-widgets in a top-level window
9
11 itk::Archetype <- itk::Toplevel
12
14 background cursor
15
16 See the "options" manual entry for details on the standard options.
17
19 Name: title
20 Class: Title
21 Command-Line Switch: -title
22
23 Sets the title that the window manager displays in the title bar
24 above the window. The default title is the null string.
25_________________________________________________________________
26
27
29 The Toplevel class inherits everything from the Archetype class, and
30 adds a Tk toplevel called the "hull" component to represent the body of
31 the mega-widget. The window class name for the hull is set to the
32 most-specific class name for the mega-widget. The protected variable
33 itk_interior contains the window path name for the "hull" component.
34 Derived classes specialize this widget by packing other widget compo‐
35 nents into the hull.
36
37 Since the hull for the Toplevel class is implemented with a Tk
38 toplevel, mega-widgets in the Toplevel class have their own toplevel
39 window. This class is used to create dialog boxes and other pop-up
40 windows.
41
42
44 Name: hull
45 Class: Toplevel
46
47 The "hull" component acts as the body for the entire mega-wid‐
48 get. Other components are packed into the hull to further spe‐
49 cialize the widget.
50
51
53 The following example implements a MessageInfo mega-widget. It creates
54 a pop-up message that the user can dismiss by pushing the "Dismiss"
55 button.
56 option add *MessageInfo.title "Notice" widgetDefault
57
58 itcl::class MessageInfo {
59 inherit itk::Toplevel
60
61 constructor {args} {
62 itk_component add dismiss {
63 button $itk_interior.dismiss -text "Dismiss" -command "destroy $itk_component(hull)"
64 }
65 pack $itk_component(dismiss) -side bottom -pady 4
66
67 itk_component add separator {
68 frame $itk_interior.sep -height 2 -borderwidth 1 -relief sunken
69 }
70 pack $itk_component(separator) -side bottom -fill x -padx 4
71
72 itk_component add icon {
73 label $itk_interior.icon -bitmap info
74 }
75 pack $itk_component(icon) -side left -padx 8 -pady 8
76
77 itk_component add infoFrame {
78 frame $itk_interior.info
79 }
80 pack $itk_component(infoFrame) -side left -expand yes -fill both -padx 4 -pady 4
81
82 itk_component add message {
83 label $itk_interior.mesg -width 20
84 } {
85 usual
86 rename -text -message message Text
87 }
88 pack $itk_component(message) -expand yes -fill both
89
90 eval itk_initialize $args
91
92 after idle [code $this centerOnScreen]
93 }
94
95 protected method centerOnScreen {} {
96 update idletasks
97 set wd [winfo reqwidth $itk_component(hull)]
98 set ht [winfo reqheight $itk_component(hull)]
99 set x [expr ([winfo screenwidth $itk_component(hull)]-$wd)/2]
100 set y [expr ([winfo screenheight $itk_component(hull)]-$ht)/2]
101 wm geometry $itk_component(hull) +$x+$y
102 }
103 }
104
105 itk::usual MessageInfo {
106 keep -background -cursor -foreground -font
107 keep -activebackground -activeforeground -disabledforeground
108 keep -highlightcolor -highlightthickness
109 }
110
111 #
112 # EXAMPLE: Create a notice window:
113 #
114 MessageInfo .m -message "File not found:\n/usr/local/bin/foo"
115
116
118 itk, Archetype, Widget, mega-widget
119
120
121
122itk 3.0 Toplevel(n)