Toplevel(3itk)
β¨ Toplevel β¨
okay bestie, welcome to the Toplevel page from the [incr Tk] manual, section 3itk π this is the one that gives your mega-widget its very own window to live in, and honestly? iconic behavior.
πΈ NAME πΈ
Toplevel β the base class for mega-widgets that live inside a top-level window πͺβ¨
π¦ INHERITANCE π¦
so the family tree is giving:
itk::Archetype <- itk::Toplevel
meaning itk::Toplevel is the child, itk::Archetype is the parent. genetics, but make it Tk π
π STANDARD OPTIONS π
these two come standard, no notes:
backgroundcursor
if you want the whole lore on these, go read the options manual entry, bestie β it's all in there π
π WIDGET-SPECIFIC OPTIONS π
okay so this one's special to Toplevel:
-titleβ Name:title, Class:Title, Command-Line Switch:-title- sets the title that the window manager shows in the title bar above the window π·οΈ
- the default title is the null string (so, empty, blank, a whole lotta nothing π)
π DESCRIPTION π
so here's the tea β Toplevel inherits everything from the Archetype class β every last bit β and then adds a Tk toplevel called the "hull" component to represent the body of the mega-widget. the hull is basically the main character's body, and the window class name for the hull is set to the most-specific class name for the mega-widget. very "dress for the job you want" energy β¨
the protected variable itk_interior holds the window path name for the "hull" component. and derived classes specialize this widget by packing other widget components into the hull β like accessorizing, but with widgets π
and because the hull for the Toplevel class is implemented with a Tk toplevel, mega-widgets in the Toplevel class get their own toplevel window. that's the whole point, that's the serve πββοΈ this class is used to create dialog boxes and other pop-up windows. pop off, fr fr π₯
π§ COMPONENTS π§
hullβ Name:hull, Class:Toplevel- the "hull" component acts as the body for the entire mega-widget π«Ά
- other components get packed into the hull to further specialize the widget β that's how you build the whole look, layer by layer π
β EXAMPLE β
not me giving you a full worked example, because I love you π«Ά the following example implements a MessageInfo mega-widget. it creates a pop-up message that the user can dismiss by pushing the "Dismiss" button.
option add *MessageInfo.title "Notice" widgetDefault
itcl::class MessageInfo {
inherit itk::Toplevel
constructor {args} {
itk_component add dismiss {
button $itk_interior.dismiss -text "Dismiss" -command "destroy $itk_component(hull)"
}
pack $itk_component(dismiss) -side bottom -pady 4
itk_component add separator {
frame $itk_interior.sep -height 2 -borderwidth 1 -relief sunken
}
pack $itk_component(separator) -side bottom -fill x -padx 4
itk_component add icon {
label $itk_interior.icon -bitmap info
}
pack $itk_component(icon) -side left -padx 8 -pady 8
itk_component add infoFrame {
frame $itk_interior.info
}
pack $itk_component(infoFrame) -side left -expand yes -fill both -padx 4 -pady 4
itk_component add message {
label $itk_interior.mesg -width 20
} {
usual
rename -text -message message Text
}
pack $itk_component(message) -expand yes -fill both
eval itk_initialize $args
after idle [code $this centerOnScreen]
}
protected method centerOnScreen {} {
update idletasks
set wd [winfo reqwidth $itk_component(hull)]
set ht [winfo reqheight $itk_component(hull)]
set x [expr ([winfo screenwidth $itk_component(hull)]-$wd)/2]
set y [expr ([winfo screenheight $itk_component(hull)]-$ht)/2]
wm geometry $itk_component(hull) +$x+$y
}
}
itk::usual MessageInfo {
keep -background -cursor -foreground -font
keep -activebackground -activeforeground -disabledforeground
keep -highlightcolor -highlightthickness
}
#
# EXAMPLE: Create a notice window:
#
MessageInfo .m -message "File not found:\n/usr/local/bin/foo"
π KEYWORDS π
itk, Archetype, Widget, mega-widget β that's the tag cloud, bestie π·οΈβ¨
and that's the whole page! this was itk version 3.0, Toplevel(3itk), and yeah β ily, go build something gorgeous with it πππ¦ no cap, periodt.
π¦ where this page comes from
- debian trixie: tk-itk4-doc 4.2.5~20240521-1 Β· BSD-Tcl
- ubuntu questing: tk-itk4-doc 4.2.5~20240521-1
- ubuntu resolute: tk-itk4-doc 4.2.5~20240521-1build1 Β· BSD-Tcl
- ubuntu stonking: tk-itk4-doc 4.2.7~20260303-2 Β· BSD-Tcl
- Copyright (c) 1993-1998 Lucent Technologies, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms