summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fdialog.html
blob: 1801278aac2f3e15d9548bb997c638497ad5b194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 <h1>Tkinter Dialogs</h1> <section id="module-tkinter.simpledialog"> <span id="tkinter-simpledialog-standard-tkinter-input-dialogs"></span><h2>tkinter.simpledialog — Standard Tkinter input dialogs</h2> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/tkinter/simpledialog.py">Lib/tkinter/simpledialog.py</a></p>  <p>The <a class="reference internal" href="#module-tkinter.simpledialog" title="tkinter.simpledialog: Simple dialog windows (Tk)"><code>tkinter.simpledialog</code></a> module contains convenience classes and functions for creating simple modal dialogs to get a value from the user.</p> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.simpledialog.askfloat">
<code>tkinter.simpledialog.askfloat(title, prompt, **kw)</code> </dt> <dt class="sig sig-object py" id="tkinter.simpledialog.askinteger">
<code>tkinter.simpledialog.askinteger(title, prompt, **kw)</code> </dt> <dt class="sig sig-object py" id="tkinter.simpledialog.askstring">
<code>tkinter.simpledialog.askstring(title, prompt, **kw)</code> </dt> <dd>
<p>The above three functions provide dialogs that prompt the user to enter a value of the desired type.</p> </dd>
</dl> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.simpledialog.Dialog">
<code>class tkinter.simpledialog.Dialog(parent, title=None)</code> </dt> <dd>
<p>The base class for custom dialogs.</p> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.simpledialog.Dialog.body">
<code>body(master)</code> </dt> <dd>
<p>Override to construct the dialog’s interface and return the widget that should have initial focus.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.simpledialog.Dialog.buttonbox">
<code>buttonbox()</code> </dt> <dd>
<p>Default behaviour adds OK and Cancel buttons. Override for custom button layouts.</p> </dd>
</dl> </dd>
</dl> </section> <section id="module-tkinter.filedialog"> <span id="tkinter-filedialog-file-selection-dialogs"></span><h2>tkinter.filedialog — File selection dialogs</h2> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/tkinter/filedialog.py">Lib/tkinter/filedialog.py</a></p>  <p>The <a class="reference internal" href="#module-tkinter.filedialog" title="tkinter.filedialog: Dialog classes for file selection (Tk)"><code>tkinter.filedialog</code></a> module provides classes and factory functions for creating file/directory selection windows.</p> <section id="native-load-save-dialogs"> <h3>Native Load/Save Dialogs</h3> <p>The following classes and functions provide file dialog windows that combine a native look-and-feel with configuration options to customize behaviour. The following keyword arguments are applicable to the classes and functions listed below:</p>          <p><strong>Static factory functions</strong></p> <p>The below functions when called create a modal, native look-and-feel dialog, wait for the user’s selection, then return the selected value(s) or <code>None</code> to the caller.</p> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.filedialog.askopenfile">
<code>tkinter.filedialog.askopenfile(mode='r', **options)</code> </dt> <dt class="sig sig-object py" id="tkinter.filedialog.askopenfiles">
<code>tkinter.filedialog.askopenfiles(mode='r', **options)</code> </dt> <dd>
<p>The above two functions create an <a class="reference internal" href="#tkinter.filedialog.Open" title="tkinter.filedialog.Open"><code>Open</code></a> dialog and return the opened file object(s) in read-only mode.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.filedialog.asksaveasfile">
<code>tkinter.filedialog.asksaveasfile(mode='w', **options)</code> </dt> <dd>
<p>Create a <a class="reference internal" href="#tkinter.filedialog.SaveAs" title="tkinter.filedialog.SaveAs"><code>SaveAs</code></a> dialog and return a file object opened in write-only mode.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.filedialog.askopenfilename">
<code>tkinter.filedialog.askopenfilename(**options)</code> </dt> <dt class="sig sig-object py" id="tkinter.filedialog.askopenfilenames">
<code>tkinter.filedialog.askopenfilenames(**options)</code> </dt> <dd>
<p>The above two functions create an <a class="reference internal" href="#tkinter.filedialog.Open" title="tkinter.filedialog.Open"><code>Open</code></a> dialog and return the selected filename(s) that correspond to existing file(s).</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.filedialog.asksaveasfilename">
<code>tkinter.filedialog.asksaveasfilename(**options)</code> </dt> <dd>
<p>Create a <a class="reference internal" href="#tkinter.filedialog.SaveAs" title="tkinter.filedialog.SaveAs"><code>SaveAs</code></a> dialog and return the selected filename.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="tkinter.filedialog.askdirectory">
<code>tkinter.filedialog.askdirectory(**options)</code> </dt> <dd> </dd>
</dl> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.filedialog.Open">
<code>class tkinter.filedialog.Open(master=None, **options)</code> </dt> <dt class="sig sig-object py" id="tkinter.filedialog.SaveAs">
<code>class tkinter.filedialog.SaveAs(master=None, **options)</code> </dt> <dd>
<p>The above two classes provide native dialog windows for saving and loading files.</p> </dd>
</dl> <p><strong>Convenience classes</strong></p> <p>The below classes are used for creating file/directory windows from scratch. These do not emulate the native look-and-feel of the platform.</p> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.filedialog.Directory">
<code>class tkinter.filedialog.Directory(master=None, **options)</code> </dt> <dd>
<p>Create a dialog prompting the user to select a directory.</p> </dd>
</dl> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The <em>FileDialog</em> class should be subclassed for custom event handling and behaviour.</p> </div> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog">
<code>class tkinter.filedialog.FileDialog(master, title=None)</code> </dt> <dd>
<p>Create a basic file selection dialog.</p> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.cancel_command">
<code>cancel_command(event=None)</code> </dt> <dd>
<p>Trigger the termination of the dialog window.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.dirs_double_event">
<code>dirs_double_event(event)</code> </dt> <dd>
<p>Event handler for double-click event on directory.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.dirs_select_event">
<code>dirs_select_event(event)</code> </dt> <dd>
<p>Event handler for click event on directory.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.files_double_event">
<code>files_double_event(event)</code> </dt> <dd>
<p>Event handler for double-click event on file.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.files_select_event">
<code>files_select_event(event)</code> </dt> <dd>
<p>Event handler for single-click event on file.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.filter_command">
<code>filter_command(event=None)</code> </dt> <dd>
<p>Filter the files by directory.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.get_filter">
<code>get_filter()</code> </dt> <dd>
<p>Retrieve the file filter currently in use.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.get_selection">
<code>get_selection()</code> </dt> <dd>
<p>Retrieve the currently selected item.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.go">
<code>go(dir_or_file=os.curdir, pattern='*', default='', key=None)</code> </dt> <dd>
<p>Render dialog and start event loop.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.ok_event">
<code>ok_event(event)</code> </dt> <dd>
<p>Exit dialog returning current selection.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.quit">
<code>quit(how=None)</code> </dt> <dd>
<p>Exit dialog returning filename, if any.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.set_filter">
<code>set_filter(dir, pat)</code> </dt> <dd>
<p>Set the file filter.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.set_selection">
<code>set_selection(file)</code> </dt> <dd>
<p>Update the current file selection to <em>file</em>.</p> </dd>
</dl> </dd>
</dl> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.filedialog.LoadFileDialog">
<code>class tkinter.filedialog.LoadFileDialog(master, title=None)</code> </dt> <dd>
<p>A subclass of FileDialog that creates a dialog window for selecting an existing file.</p> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.LoadFileDialog.ok_command">
<code>ok_command()</code> </dt> <dd>
<p>Test that a file is provided and that the selection indicates an already existing file.</p> </dd>
</dl> </dd>
</dl> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.filedialog.SaveFileDialog">
<code>class tkinter.filedialog.SaveFileDialog(master, title=None)</code> </dt> <dd>
<p>A subclass of FileDialog that creates a dialog window for selecting a destination file.</p> <dl class="py method"> <dt class="sig sig-object py" id="tkinter.filedialog.SaveFileDialog.ok_command">
<code>ok_command()</code> </dt> <dd>
<p>Test whether or not the selection points to a valid file that is not a directory. Confirmation is required if an already existing file is selected.</p> </dd>
</dl> </dd>
</dl> </section> </section> <section id="module-tkinter.commondialog"> <span id="tkinter-commondialog-dialog-window-templates"></span><h2>tkinter.commondialog — Dialog window templates</h2> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/tkinter/commondialog.py">Lib/tkinter/commondialog.py</a></p>  <p>The <a class="reference internal" href="#module-tkinter.commondialog" title="tkinter.commondialog: Tkinter base class for dialogs (Tk)"><code>tkinter.commondialog</code></a> module provides the <a class="reference internal" href="#tkinter.commondialog.Dialog" title="tkinter.commondialog.Dialog"><code>Dialog</code></a> class that is the base class for dialogs defined in other supporting modules.</p> <dl class="py class"> <dt class="sig sig-object py" id="tkinter.commondialog.Dialog">
<code>class tkinter.commondialog.Dialog(master=None, **options)</code> </dt> <dd>
<dl class="py method"> <dt class="sig sig-object py" id="tkinter.commondialog.Dialog.show">
<code>show(color=None, **options)</code> </dt> <dd>
<p>Render the Dialog window.</p> </dd>
</dl> </dd>
</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p>Modules <a class="reference internal" href="tkinter.messagebox#module-tkinter.messagebox" title="tkinter.messagebox: Various types of alert dialogs (Tk)"><code>tkinter.messagebox</code></a>, <a class="reference internal" href="../tutorial/inputoutput#tut-files"><span class="std std-ref">Reading and Writing Files</span></a></p> </div> </section> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
    <a href="https://docs.python.org/3.12/library/dialog.html" class="_attribution-link">https://docs.python.org/3.12/library/dialog.html</a>
  </p>
</div>