Dialogs
The TclTk package exports a number of dialog widgets provided by Tk. Dialog options are specified as key => val pairs where key is the option name (a string, a symbol, or a Tcl object) without its leading hyphen and val is the option value. The value returned returned when the dialog is closed depend on the type of dialog, it is usually a string but it may also be a vector of strings (for instance, if multiple selection is allowed in the tk_getOpenFile dialog).
For example:
answer = tk_messageBox(:message => "Really quit?", :icon => :question, :type => :yesno,
:detail => "Select \"Yes\" to make the application exit")
if answer == "yes"
quit()
elseif answer == "no"
tk_messageBox(:message => "I know you like this application!", :type => :ok)
endtk_start is automatically called by the dialog widgets.
Choosing a color
Interactively choosing a color can be done by (using ColorTypes is to import RGB among others):
using ColorTypes
color = tk_chooseColor(:title => "Choose a nice color", :initialcolor => RGB(1.0, 0.867, 0.267))Which gives:

If the user cancel the operation of close the dialog window, nothing is returned; otherwise, the returned color can be used to configure a Tk widget. For example:
top = TkToplevel(interp, :background => color)Language for messages
The text of standard labels is automatically chosen ny Tk according to locale settings. You may want to set one of the environment variables LC_ALL, LC_MESSAGES, or LANG to set the language for dialog widgets before starting TclTk. For example:
ENV["LC_ALL"] = "en_US"
using TclTkStandard dialogs
The following Tk dialog widgets are available:
TclTk.Impl.tk_chooseColor — Function
tk_chooseColor(interp=TclInterp(), option => value, ...)Pop up a Tk dialog box for the user to select a color and return the chosen color as an instance of TkRGB{UInt8} or nothing if the user cancels the dialog. Tcl interpreter interp is used to run the dialog.
Options
Symbols and strings are equivalent for specifying the option names and their values. Available options are:
Option
:parentspecifies the logical parent of the message box. The color dialog box is displayed on top of its parent window.Option
:titlespecifies the title of the message box.Option
:initialcolorspecifies the color to display in the color dialog when it pops up. The value of this option can be a string like"orange"or"#ff03ae"or an instance of a sub-type ofTkColor.
See also
tk_chooseDirectory, tk_getOpenFile, tk_getSaveFile, and tk_messageBox.
TclTk.Impl.tk_chooseDirectory — Function
tk_chooseDirectory(interp=TclInterp(), option => value, ...) -> dir::StringPop up a Tk dialog box for the user to select a directory and return the chosen directory name (an empty string if none). Tcl interpreter interp is used to run the dialog. Available keywords are:
Options
Symbols and strings are equivalent for specifying the option names and their values. Available options are:
Option
:parentspecifies the window of the logical parent of the message box. The message box is displayed on top of its parent window.Option
:titlespecifies the title of the message box. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.Option
:messagespecifies the message to display in this message box. The default value is an empty string. This is only available on Mac OS X.Option
:initialdirspecifies that the directories in directory should be displayed when the dialog pops up. If this parameter is not specified, the initial directory defaults to the current working directory on non-Windows systems and on Windows systems prior to Vista. On Vista and later systems, the initial directory defaults to the last user-selected directory for the application. If the parameter specifies a relative path, the return value will convert the relative path to an absolute path.Option
:mustexistspecifies whether the user may specify non-existent directories. If this parameter is true, then the user may only select directories that already exist.Option
:commandspecifies the prefix of a Tcl command to invoke when the user closes the dialog. The actual command consists of string followed by a space and the name of the button clicked by the user to close the dialog. This is only available on Mac OS X.
See also
tk_chooseColor, tk_getOpenFile, tk_getSaveFile, and tk_messageBox.
TclTk.Impl.tk_getOpenFile — Function
tk_getOpenFile(interp=TclInterp(), option => value, ...)Pop up a Tk dialog box for the user to select a file to open and return the name of the chosen file (an empty string if none). Tcl interpreter interp is used to run the dialog.
Options
Symbols and strings are equivalent for specifying the option names and their values. Available options are:
Option
:parentspecifies the path of the logical parent of the file dialog. The file dialog is displayed on top of its parent window. On Mac OS X, this turns the file dialog into a sheet attached to the parent window.Option
:titlespecifies a string to display as the title of the dialog box. If this option is not specified, then a default title is displayed.Option
:messageSpecifies a message to include in the client area of the dialog. This is only available on Mac OS X.Option
:initialdirspecifies the directory in which the files should be displayed when the dialog pops up. If this parameter is not specified, the initial directory defaults to the current working directory on non-Windows systems and on Windows systems prior to Vista. On Vista and later systems, the initial directory defaults to the last user-selected directory for the application. If the parameter specifies a relative path, the return value will convert the relative path to an absolute path.Option
:initialfilespecifies a filename to be displayed in the dialog when it pops up.Option
:multiplespecifies whether the user can choose multiple files from the Open dialog. If multiple files are chosen, a vector of strings is returned.Option
:defaultextensionspecifies a string that will be appended to the filename if the user enters a filename without an extension. The default value is the empty string, which means no extension will be appended to the filename in any case. This option is ignored on Mac OS X, which does not require extensions to filenames, and the UNIX implementation guesses reasonable values for this from thefiletypesoption when this is not supplied.If a file types listbox exists in the file dialog on the particular platform, option
:filetypesgives the filetypes in this listbox. When the user choose a filetype in the listbox, only the files of that type are listed. If this option is unspecified, or if it is set to the empty list, or if the File types listbox is not supported by the particular platform then all files are listed regardless of their types. See Tk manual for more details.Option
:typevariablespecifies the name of a global Tcl variable used to preselect which filter is used from filterList when the dialog box is opened and is updated when the dialog box is closed, to the last selected filter. The variable is read once at the beginning to select the appropriate filter. If the variable does not exist, or its value does not match any filter typename, or is empty ({}), the dialog box will revert to the default behavior of selecting the first filter in the list. If the dialog is canceled, the variable is not modified.Option
:commandspecifies the prefix of a Tcl command to invoke when the user closes the dialog after having selected an item. This callback is not called if the user cancelled the dialog. The actual command consists of thecommandstring followed by a space and the value selected by the user in the dialog. This is only available on Mac OS X.
See also
tk_getOpenFile, tk_chooseColor, tk_chooseDirectory, and tk_messageBox.
TclTk.Impl.tk_getSaveFile — Function
tk_getSaveFile(interp=TclInterp(), option => value, ...)Pop up a Tk dialog box for the user to select a file to save and return the name of the chosen file (an empty string if none). Tcl interpreter interp is used to run the dialog.
Options
Symbols and strings are equivalent for specifying the option names and their values. Available options are:
For options
:parent,:title,:message,:initialdir,:initialfile,:defaultextension,:filetypes,:typevariable, and:command, seetk_getSaveFile.Option
:confirmoverwriteconfigures how the Save dialog reacts when the selected file already exists, and saving would overwrite it. A true value requests a confirmation dialog be presented to the user. A false value requests that the overwrite take place without confirmation.
See also
tk_getSaveFile, tk_chooseColor, tk_chooseDirectory, and tk_messageBox.
TclTk.Impl.tk_messageBox — Function
tk_messageBox(interp=TclInterp(), option => value, ...) -> answer::StringPop up a Tk message box dialog and return the name of the selected button. Tcl interpreter interp is used to run the dialog.
Options
Symbols and strings are equivalent for specifying the option names and their values. Available options are:
Option
:parentspecifies the window of the logical parent of the message box. The message box is displayed on top of its parent window.Option
:titlespecifies the title of the message box. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.Option
:messagespecifies the message to display in this message box. The default value is an empty string.Option
:detailspecifies an auxiliary message to the main message. The message detail will be presented beneath the main message and, where supported by the OS, in a less emphasized font than the main message.Option
:iconspecifies an icon to display::error,:info,:questionor:warning. By default, the:infoicon is displayed.Option
:typespecifies which predefined set of buttons is displayed. The following values are possible::abortretryignoreto display three buttons whose symbolic names are:abort,:retryand:ignore.:okto display one button whose symbolic name is:ok.:okcancelto display two buttons whose symbolic names are:okand:cancel.:retrycancelto display two buttons whose symbolic names are:retryand:cancel.:yesnoto display two buttons whose symbolic names are:yesand:no.:yesnocancelto display three buttons whose symbolic names are:yes,:noand:cancel.
Option
:defaultgives the name of the default button for this message window (:ok,:cancel, and so on). See keywordtypefor a list of the button names. If this option is not specified, the first button in the dialog will be made the default.Option
:commandspecifies the prefix of a Tcl command to invoke when the user closes the dialog. The actual command consists of string followed by a space and the name of the button clicked by the user to close the dialog. This is only available on Mac OS X.
Examples
answer = tk_messageBox(:message => "Really quit?", :icon => :question, :type => :yesno,
:detail => "Select "Yes" to make the application exit")
if answer == "yes"
quit()
elseif answer == "no"
tk_messageBox(:message => "I know you like this application!", :type => :ok)
endSee also
tk_chooseColor, tk_chooseDirectory, tk_getOpenFile, and and tk_getSaveFile.