Displaying a message box

The tk_messageBox command displays a message window with a defined message, an icon and a collection of command buttons and waits on the user's response. The return value provided is the symbolic value (see the type option in the following table) assigned to the button selected.

The syntax is as follows:

	tk_messageBox option value …

The tk_messageBox command accepts one or more option value pairs as detailed below. If no option value pairs are provided the command will display an empty window with an OK button.

Option

Interpretation

-default name

Designates which button is the default.

-detail string

Displays a secondary message to the message provided by the –message option.

-icon name

Sets the icon to display, based on the value referenced by name. Acceptable values are: error, info (default), question, or warning.

-message string

Sets the message to be displayed

-parent window

Specifies the parent of the dialog. The dialog is displayed on top of the parent.

-title string

Sets the text to be displayed in the dialog title bar.

-type name

Specifies the button set to be utilized by the dialog. Acceptable values are:

abortretryignore: Displays three buttons with the symbolic names abort, retry, and ignore.

ok: Displays a single button with the symbolic name ok.

okcancel: Displays two buttons with the symbolic names ok and cancel.

retrycancel: Displays two buttons with the symbolic names retry and cancel.

yesno: Displays two buttons with the symbolic names yes and no.

yesnocancel: Displays three buttons with the symbolic names yes, no, and cancel.

How to do it…

In the following example, we will display a message box and assign the return value to a named variable. Enter the following commands:


1 % set response [tk_messageBox -message "Confirm Exit" -icon question - 
type okcancel -detail "Please select "OK" to exit"

You should now see the following dialog displayed.

How to do it…

Note that in your shell window, the input line is no longer active and if this dialog were being displayed from an application, we could no longer interact with any other widgets in the same application. This is due to the fact that the application (in this case, the wish shell) is awaiting a response. Click on the OK button and you will notice that the symbolic value of ok is displayed on the command line and you can now interact with your shell. Enter the following command to confirm that the symbolic value was assigned to the named variable:


2 % puts $response
ok

How it works…

Based on the option value pairs provided, Tk has displayed a tk_messageBox with the messages and buttons desired. On completion, the return value of the button selected was assigned to a named variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.134.130