pythonware.com | products ::: library ::: search ::: daily Python-URL! |
Data EntryData EntryThe tkSimpleDialog module provides an interface to the following simple dialogs. StringsThe askstring function in the tkSimpleDialog module prompts the user for a string. You specify the dialog title and the prompt string, and the function returns when the user closes the dialog. The prompt string may include newline characters. tkSimpleDialog.askstring(title, prompt [,options]). Ask the user to enter an string value. If the user pressed Enter, or clicked OK, the function returns the string. If the user closed the dialog by pressing Escape, clicking Cancel, or explicitly via the window manager, this function returns None. Figure 9-4. askstring The following options can be used with this function: Table 9-2. askstring Options
Numeric ValuesThe askinteger and askfloat functions is similar to askstring, but they only accept integers and float values, respectively. You can also use the minvalue and maxvalue options to limit the input range: tkSimpleDialog.askinteger(title, prompt [,options]). Ask the user to enter an integer value. If the entered value is not a valid integer or floating point value, a message box is displayed, and the dialog is not closed. As with the askstring function, the function returns None if the dialog box is cancelled. tkSimpleDialog.askfloat(title, prompt [,options]). Same, but returns a floating point value. Figure 9-5. askinteger, askfloat The following options can be used with these functions: Table 9-3. askinteger and askfloat options
File NamesThe tkFileDialog module (included in the standard dialog kit described earlier) can be used to get a filename from the user. The module provides two convenience functions, one to get an existing filename so you can open it, and one to get a new filename, to save things into. tkFileDialog.askopenfilename([options]). If the dialog is cancelled by the user, the function returns None. tkFileDialog.asksaveasfilename([options]). Figure 9-6. askopenfilename, asksaveasfilename The following options can be used with the askopenfilename and asksavefilename functions: Table 9-4. askopenfilename options
ColorsThe tkColorChooser module (included in the standard dialog kit described earlier) can be used to specify an RGB color value. tkColorChooser.askcolor([color [,options]]). The convenience function returns two values; the first is the color as a RGB triplet (a 3-tuple containing the red, green and blue values as integers in the range 0-255), the second a Tk color string. To preset a color when you display the dialog, you can pass a color (in either format) to the function. If the dialog is cancelled, the function returns (None, None) Figure 9-7. askcolor (in Swedish) The following options can be used with the askcolor function: Table 9-5. askcolor Options
|