pops up a message window and waits for user response.
http://purl.org/tcl/home/man/tcl8.4/TkCmd/messageBox.htm
See also: messageBox.
This command is recommended over use of tk_dialog.
SYNOPSIS
tk_messageBox ?option value ...?
DESCRIPTION
This procedure creates and displays a message window with an application-specified message, an icon and a set of buttons. Each of the buttons in the message window is identified by a unique symbolic name (see the -type options). After the message window is popped up, tk_messageBox waits for the user to select one of the buttons. Then it returns the symbolic name of the selected button. The following option-value pairs are supported:
-default name
Name gives the symbolic name of the default button for this message window ('ok', 'cancel', and so on). See -type for a list of the symbolic names. If this option is not specified, the first button in the dialog will be made the default.
-icon iconImage
Specifies an icon to display. IconImage must be one of the following: error, info, question or warning. If this option is not specified, then the info icon will be displayed.
-message string
Specifies the message to display in this message box.
-parent window
Makes window the logical parent of the message box. The message box is displayed on top of its parent window.
-title titleString
Specifies a string to display as the title of the message box. The default value is an empty string.
-type predefinedType
Arranges for a predefined set of buttons to be displayed. The following values are possible for predefinedType:
EXAMPLE
set answer [tk_messageBox -message "Really quit?" -type yesno -icon question] switch -- $answer { yes exit no {tk_messageBox -message "I know you like this application!" -type ok} }
With recent versions, the Windows messageBox is "native", while the Unix one continues to rely on the implementation visible in ./library/msgbox.tcl. Before version 8.something, both Win* and Unix used msgbox.tcl [what about MacOS?]. Notice that this means that, if there's something about messageBox you don't like, you have the source code readily available for your enhancements.
[Detail example of how to do this needed right here.]
DKF: No. There has never been a non-native version of tk_messageBox on Windows and Macintosh, though tk_dialog is an approximation (and implemented purely in Tcl scripts) on all platforms.
Donald Arseneau mentions on comp.lang.tcl that this widget is not written to be re-entrant. The result of this means that if there are two instances of tk_messageBox opened at the same time, a button clicked in one of them is seen by all of them! This is a bug in the widget that has been submitted to the sf.net bug database, but doesn't appear to be resolved as of Fall 2003.
[Insert example of how to use option database with messageBox.]
On Unix, the default font for message boxes is Times 18, which is way too fat for longer text. Before creating a messageBox, just add the line
option add *Dialog.msg.font {Times 12}
to get a better readable font (won't hurt in Windows, where native message boxes are used anyway). (RS)
The wraplength also defaults to 3 inches but can be overriden the same way for long messages (BBH)
option add *Dialog.msg.wrapLength 6i
Martin Lemburg Because of the need to have a messagebox in the tclsh, I wrote a tclsh version ... tcl_messageBox. To download the stubs enabled version (tcl v8.1 and higher) use
ftp://ftp.dcade.de/pub/ml/tcl/packages/tcl_messageBox10.zip (package only) ftp://ftp.dcade.de/pub/ml/tcl/packages/tcl_messageBox10.all.zip (includes the source, project files, etc.)
The syntax is simular to the tk_messageBox:
tcl_messageBox ?option optionArg option optionArg ...?
options:
Harald Oehlmann On windows, the tk_messageBox command sets the toplevel . to the top of the window stacking order. After the message box, the toplevel . gets the focus.
To "repair" this behavior on tcl8.4 one can protect the windows over . by
wm attributes -topmost 1
and save the focus over the routine.
# tk_messageBox for Windows which keeps focus and stacking order proc messageBox args { # > Save focus set Focus [focus] # > Get the toplevels above . and set topmost attribute set lWindows [wm stackorder .] set TopPos [lsearch $lWindows .] if {-1 != $TopPos && $TopPos != [llength $lWindows]} { incr TopPos set lWindows [lrange $lWindows $TopPos end] foreach Wi $lWindows { wm attributes $Wi -topmost 1 } } else { unset lWindows } } # > invoke message box set Res [eval tk_messageBox $args] set Res [eval tk_messageBox $args] # > unset topmost attribute if {[info exists lWindows]} { foreach Wi $lWindows { wm attributes $Wi -topmost 0 } } # > Restore focus # Set focus to last widget if we had the focus before # otherwise set it to the topmost window if {0 < [string length $Focus]} { focus -force $Focus } elseif {[info exists lWindows]} { focus -force [lindex $lWindows end] } return $Res } # Test program for demonstration: foreach Wi {. .t1 .t2} { catch {toplevel $Wi} pack [button $Wi.b1 -text messageBox -command "messageBox -message So..."] pack [button $Wi.b2 -text tk_messageBox -command "tk_messageBox -message well..."] }
[Incorporate material from this comp.lang.tcl thread [L1 ].]
RS has grown into the habit of coding
set about "Short descriptive text for the app, at beginning of source file (also serves for some documentation)" ... button .a -text About -command [tk_messageBox -message $about] ...
Category Dialog - Category Command - Tk syntax help - Arts and Crafts of Tcl-Tk Programming