programming.nbk: Home | Index | Next Page: Tk: Widgets | Previous Page: Tk: radiobutton


 Tk: toplevel

toplevel is a widget. This can be used to create custom dialog boxes. A toplevel is similar to a frame except that it is created as a top-level window: its X parent is the root window of a screen rather than the logical parent from its path name. The primary purpose of a toplevel is to serve as a container for dialog boxes and other collections of widgets. The only visible features of a toplevel are its background color and an optional 3-D border to make the toplevel appear raised or sunken.

One can use toplevel to create new windows. The widgets can be packed inside it in the same way widgets are packed inside a frame. An example...

#A procedure to make a toplevel window
proc makeTop { } {
	toplevel .top ;#Make the window
	#Put things in it
	label .top.lab -text "This is Toplevel Window" -font "ansi 12 bold"
	text .top.txt 
	.top.txt insert end "Widgets can be packed in this window."
	#An option to close the window.
	button .top.but -text "Close" -command { destroy .top }
	#Pack everything
	pack .top.lab .top.txt .top.but
}

label .lab -text "This is the root window." -font "ansi 12 bold"
button .but -text "Click to Create Toplevel" -command { makeTop }
pack .lab .but

programming.nbk: Home | Index | Next Page: Tk: Widgets | Previous Page: Tk: radiobutton


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time