Dialog Class

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
We have created a widget named ".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
This changes the appearance of the button, and has the side effect of binding the Return key so that invokes the button. Try placing the mouse in the window and hitting Return.

You can also directly invoke a button from a script using the invoke method:

.m invoke pushme
You can insert a bitmap into the message window:
.m configure -bitmap questhead
The value, "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
You can remove the Dialog object with the following command:
delete object .m

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}
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.

Tycho Home Page


Copyright © 1996, The Regents of the University of California. All rights reserved.
Last updated: 96/12/17, comments to: eal@eecs.berkeley.edu