The common base class for all dialogs with the user is the Dialog class.
You can use this class to create customized interactions.
For example,
::tycho::Dialog .m -text {A dialog with a customized button}
.m addButton pushme -text {Push Me} -command {::tycho::post thanks}
wm deiconify .m
.m
and inserted into it a button
named pushme
. The
addButton
method is
defined in the class dialog. The button is bound to the command
::tycho::post thanks
.
This class is derived from
TopLevel, so you can center it
on the screen, freeze the window size, etc.
You can mark the button as a
default
button with the following command:
.m default pushme
Return
key so that invokes the button. Try placing
the mouse in the window and hitting Return
.
Usually, you will also want to bind a keyboard shortcut for
invoking the button. This is done by giving a -underline
option as follows:
.m addButton x -text Bell -underline 0 -command bell
b
or B
causes the bell to ring.
You can also directly invoke a button from a script using the
invoke
method:
.m invoke pushme
.m configure -bitmap questhead
questhead
,
is the name of a built-in bitmap.
Other particularly useful ones are
error
,
info
,
question
,
hourglass
, and
warning
.
As with any option, we could have specified the -bitmap
option
in the original command creating the widget.
You can also insert an image
created with the "image create
"
command, using the Tk photo widget.
image create photo ptgif -file $TYCHO/kernel/img/tychologo.gif
.m configure -image ptgif
Escape
key.
There are two procedures defined in the Dialog class to support
creation of
modal
and non-modal dialog boxes. Each of them takes the
name of a class (which must be derived from Dialog), an instance
name, and optional set of arguments, and creates an instance of the class.
The new
procedure creates a non-modal
dialog:
::tycho::Dialog::new Message .y -text \
{This message is automatically mapped}
Message
class
is a simple class derived from Dialog
that adds an "OK" button.
The only advantage of using this feature is that message automatically
appears in the center of the screen, without having to issue a second
command. This is not a big advantage.
The Dialog wait
procedure can be used
to map an Dialog object to the screen and then wait for the object to
be destroyed.