The examples here all refer to the dialogs module.
This is the simplest kind of dialog box: a one-line edit control with [Ok] and [Cancel].
1 2 3 | from winsys import dialogs
name = dialogs.dialog ("What is your name?", ("Name", ""))
|
Ask the user for a filename, check that the file exists, and then use os.startfile to open the file. Allow the user to type the filename in, drag-and-drop a file from Explorer, or select from a dialog box.
1 2 3 4 5 6 7 8 9 10 11 12 13 | import os
from winsys import dialogs, fs
DEFAULT = "temp.csv"
filename, = dialogs.dialog (
"Open a filename",
("Filename", DEFAULT, dialogs.get_filename)
)
if not fs.file (filename):
raise RuntimeError ("%s does not exist" % filename)
else:
os.startfile (filename)
|
All edit controls accept files drag/dropped from Explorer. In addition, by specifying a third field for the “Filename” input, we can call out to another dialog box to select the file. Here we use the one supplied by winsys, but the only requirement for the callback is that it return a string or None to indicate no change.
A fs.Entry object evaluates to True if the file it represents exists on the file system.