parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="Tkinter Dialogs" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/dialog.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="tkinter.simpledialog — Standard Tkinter input dialogs: Source code: Lib/tkinter/simpledialog.py The tkinter.simpledialog module contains convenience classes and functions for creating simple modal ..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_dialog_13398306.png" />15<meta property="og:image:alt" content="tkinter.simpledialog — Standard Tkinter input dialogs: Source code: Lib/tkinter/simpledialog.py The tkinter.simpledialog module contains convenience classes and functions for creating simple modal ..." />16<meta name="description" content="tkinter.simpledialog — Standard Tkinter input dialogs: Source code: Lib/tkinter/simpledialog.py The tkinter.simpledialog module contains convenience classes and functions for creating simple modal ..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>Tkinter Dialogs — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="tkinter.messagebox — Tkinter message prompts" href="tkinter.messagebox.html" />43 <link rel="prev" title="tkinter.font — Tkinter font wrapper" href="tkinter.font.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/dialog.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<li><a class="reference internal" href="#">Tkinter Dialogs</a><ul>108<li><a class="reference internal" href="#module-tkinter.simpledialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.simpledialog</span></code> — Standard Tkinter input dialogs</a></li>109<li><a class="reference internal" href="#module-tkinter.filedialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.filedialog</span></code> — File selection dialogs</a><ul>110<li><a class="reference internal" href="#native-load-save-dialogs">Native Load/Save Dialogs</a></li>111</ul>112</li>113<li><a class="reference internal" href="#module-tkinter.commondialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.commondialog</span></code> — Dialog window templates</a></li>114</ul>115</li>116</ul>117 118 </div>119 <div>120 <h4>Previous topic</h4>121 <p class="topless"><a href="tkinter.font.html"122 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.font</span></code> — Tkinter font wrapper</a></p>123 </div>124 <div>125 <h4>Next topic</h4>126 <p class="topless"><a href="tkinter.messagebox.html"127 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.messagebox</span></code> — Tkinter message prompts</a></p>128 </div>129 <script>130 document.addEventListener('DOMContentLoaded', () => {131 const title = document.querySelector('meta[property="og:title"]').content;132 const elements = document.querySelectorAll('.improvepage');133 const pageurl = window.location.href.split('?')[0];134 elements.forEach(element => {135 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));136 url.searchParams.set('pagetitle', title);137 url.searchParams.set('pageurl', pageurl);138 url.searchParams.set('pagesource', "library/dialog.rst");139 element.href = url.toString();140 });141 });142 </script>143 <div role="note" aria-label="source link">144 <h3>This page</h3>145 <ul class="this-page-menu">146 <li><a href="../bugs.html">Report a bug</a></li>147 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>148 <li>149 <a href="https://github.com/python/cpython/blob/main/Doc/library/dialog.rst?plain=1"150 rel="nofollow">Show source151 </a>152 </li>153 154 </ul>155 </div>156 </nav>157 </div>158</div>159 160 161 <div class="related" role="navigation" aria-label="Related">162 <h3>Navigation</h3>163 <ul>164 <li class="right" style="margin-right: 10px">165 <a href="../genindex.html" title="General Index"166 accesskey="I">index</a></li>167 <li class="right" >168 <a href="../py-modindex.html" title="Python Module Index"169 >modules</a> |</li>170 <li class="right" >171 <a href="tkinter.messagebox.html" title="tkinter.messagebox — Tkinter message prompts"172 accesskey="N">next</a> |</li>173 <li class="right" >174 <a href="tkinter.font.html" title="tkinter.font — Tkinter font wrapper"175 accesskey="P">previous</a> |</li>176 177 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>178 <li><a href="https://www.python.org/">Python</a> »</li>179 <li class="switchers">180 <div class="language_switcher_placeholder"></div>181 <div class="version_switcher_placeholder"></div>182 </li>183 <li>184 185 </li>186 <li id="cpython-language-and-version">187 <a href="../index.html">3.15.0a6 Documentation</a> »188 </li>189 190 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>191 <li class="nav-item nav-item-2"><a href="tk.html" accesskey="U">Graphical user interfaces with Tk</a> »</li>192 <li class="nav-item nav-item-this"><a href="">Tkinter Dialogs</a></li>193 <li class="right">194 195 196 <div class="inline-search" role="search">197 <form class="inline-search" action="../search.html" method="get">198 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">199 <input type="submit" value="Go">200 </form>201 </div>202 |203 </li>204 <li class="right">205<label class="theme-selector-label">206 Theme207 <select class="theme-selector" oninput="activateTheme(this.value)">208 <option value="auto" selected>Auto</option>209 <option value="light">Light</option>210 <option value="dark">Dark</option>211 </select>212</label> |</li>213 214 </ul>215 </div> 216 217 <div class="document">218 <div class="documentwrapper">219 <div class="bodywrapper">220 <div class="body" role="main">221 222 <section id="tkinter-dialogs">223<h1>Tkinter Dialogs<a class="headerlink" href="#tkinter-dialogs" title="Link to this heading">¶</a></h1>224<section id="module-tkinter.simpledialog">225<span id="tkinter-simpledialog-standard-tkinter-input-dialogs"></span><h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.simpledialog</span></code> — Standard Tkinter input dialogs<a class="headerlink" href="#module-tkinter.simpledialog" title="Link to this heading">¶</a></h2>226<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/tkinter/simpledialog.py">Lib/tkinter/simpledialog.py</a></p>227<hr class="docutils" />228<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.simpledialog</span></code> module contains convenience classes and229functions for creating simple modal dialogs to get a value from the user.</p>230<dl class="py function">231<dt class="sig sig-object py" id="tkinter.simpledialog.askfloat">232<span class="sig-prename descclassname"><span class="pre">tkinter.simpledialog.</span></span><span class="sig-name descname"><span class="pre">askfloat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">title</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prompt</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.askfloat" title="Link to this definition">¶</a></dt>233<dt class="sig sig-object py" id="tkinter.simpledialog.askinteger">234<span class="sig-prename descclassname"><span class="pre">tkinter.simpledialog.</span></span><span class="sig-name descname"><span class="pre">askinteger</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">title</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prompt</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.askinteger" title="Link to this definition">¶</a></dt>235<dt class="sig sig-object py" id="tkinter.simpledialog.askstring">236<span class="sig-prename descclassname"><span class="pre">tkinter.simpledialog.</span></span><span class="sig-name descname"><span class="pre">askstring</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">title</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prompt</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.askstring" title="Link to this definition">¶</a></dt>237<dd><p>The above three functions provide dialogs that prompt the user to enter a value238of the desired type.</p>239</dd></dl>240 241<dl class="py class">242<dt class="sig sig-object py" id="tkinter.simpledialog.Dialog">243<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.simpledialog.</span></span><span class="sig-name descname"><span class="pre">Dialog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">parent</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">title</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.Dialog" title="Link to this definition">¶</a></dt>244<dd><p>The base class for custom dialogs.</p>245<dl class="py method">246<dt class="sig sig-object py" id="tkinter.simpledialog.Dialog.body">247<span class="sig-name descname"><span class="pre">body</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.Dialog.body" title="Link to this definition">¶</a></dt>248<dd><p>Override to construct the dialog’s interface and return the widget that249should have initial focus.</p>250</dd></dl>251 252<dl class="py method">253<dt class="sig sig-object py" id="tkinter.simpledialog.Dialog.buttonbox">254<span class="sig-name descname"><span class="pre">buttonbox</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.simpledialog.Dialog.buttonbox" title="Link to this definition">¶</a></dt>255<dd><p>Default behaviour adds OK and Cancel buttons. Override for custom button256layouts.</p>257</dd></dl>258 259</dd></dl>260 261</section>262<section id="module-tkinter.filedialog">263<span id="tkinter-filedialog-file-selection-dialogs"></span><h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.filedialog</span></code> — File selection dialogs<a class="headerlink" href="#module-tkinter.filedialog" title="Link to this heading">¶</a></h2>264<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/tkinter/filedialog.py">Lib/tkinter/filedialog.py</a></p>265<hr class="docutils" />266<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.filedialog</span></code> module provides classes and factory functions for267creating file/directory selection windows.</p>268<section id="native-load-save-dialogs">269<h3>Native Load/Save Dialogs<a class="headerlink" href="#native-load-save-dialogs" title="Link to this heading">¶</a></h3>270<p>The following classes and functions provide file dialog windows that combine a271native look-and-feel with configuration options to customize behaviour.272The following keyword arguments are applicable to the classes and functions273listed below:</p>274<blockquote>275<div><div class="line-block">276<div class="line"><em>parent</em> - the window to place the dialog on top of</div>277</div>278<div class="line-block">279<div class="line"><em>title</em> - the title of the window</div>280</div>281<div class="line-block">282<div class="line"><em>initialdir</em> - the directory that the dialog starts in</div>283</div>284<div class="line-block">285<div class="line"><em>initialfile</em> - the file selected upon opening of the dialog</div>286</div>287<div class="line-block">288<div class="line"><em>filetypes</em> - a sequence of (label, pattern) tuples, ‘*’ wildcard is allowed</div>289</div>290<div class="line-block">291<div class="line"><em>defaultextension</em> - default extension to append to file (save dialogs)</div>292</div>293<div class="line-block">294<div class="line"><em>multiple</em> - when true, selection of multiple items is allowed</div>295</div>296</div></blockquote>297<p><strong>Static factory functions</strong></p>298<p>The below functions when called create a modal, native look-and-feel dialog,299wait for the user’s selection, then return the selected value(s) or <code class="docutils literal notranslate"><span class="pre">None</span></code> to the300caller.</p>301<dl class="py function">302<dt class="sig sig-object py" id="tkinter.filedialog.askopenfile">303<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">askopenfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.askopenfile" title="Link to this definition">¶</a></dt>304<dt class="sig sig-object py" id="tkinter.filedialog.askopenfiles">305<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">askopenfiles</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.askopenfiles" title="Link to this definition">¶</a></dt>306<dd><p>The above two functions create an <a class="reference internal" href="#tkinter.filedialog.Open" title="tkinter.filedialog.Open"><code class="xref py py-class docutils literal notranslate"><span class="pre">Open</span></code></a> dialog and return the opened307file object(s) in read-only mode.</p>308</dd></dl>309 310<dl class="py function">311<dt class="sig sig-object py" id="tkinter.filedialog.asksaveasfile">312<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">asksaveasfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'w'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.asksaveasfile" title="Link to this definition">¶</a></dt>313<dd><p>Create a <a class="reference internal" href="#tkinter.filedialog.SaveAs" title="tkinter.filedialog.SaveAs"><code class="xref py py-class docutils literal notranslate"><span class="pre">SaveAs</span></code></a> dialog and return a file object opened in write-only mode.</p>314</dd></dl>315 316<dl class="py function">317<dt class="sig sig-object py" id="tkinter.filedialog.askopenfilename">318<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">askopenfilename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.askopenfilename" title="Link to this definition">¶</a></dt>319<dt class="sig sig-object py" id="tkinter.filedialog.askopenfilenames">320<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">askopenfilenames</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.askopenfilenames" title="Link to this definition">¶</a></dt>321<dd><p>The above two functions create an <a class="reference internal" href="#tkinter.filedialog.Open" title="tkinter.filedialog.Open"><code class="xref py py-class docutils literal notranslate"><span class="pre">Open</span></code></a> dialog and return the322selected filename(s) that correspond to existing file(s).</p>323</dd></dl>324 325<dl class="py function">326<dt class="sig sig-object py" id="tkinter.filedialog.asksaveasfilename">327<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">asksaveasfilename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.asksaveasfilename" title="Link to this definition">¶</a></dt>328<dd><p>Create a <a class="reference internal" href="#tkinter.filedialog.SaveAs" title="tkinter.filedialog.SaveAs"><code class="xref py py-class docutils literal notranslate"><span class="pre">SaveAs</span></code></a> dialog and return the selected filename.</p>329</dd></dl>330 331<dl class="py function">332<dt class="sig sig-object py" id="tkinter.filedialog.askdirectory">333<span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">askdirectory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.askdirectory" title="Link to this definition">¶</a></dt>334<dd><div class="line-block">335<div class="line">Prompt user to select a directory.</div>336<div class="line">Additional keyword option:</div>337<div class="line-block">338<div class="line"><em>mustexist</em> - determines if selection must be an existing directory.</div>339</div>340</div>341</dd></dl>342 343<dl class="py class">344<dt class="sig sig-object py" id="tkinter.filedialog.Open">345<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">Open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.Open" title="Link to this definition">¶</a></dt>346<dt class="sig sig-object py" id="tkinter.filedialog.SaveAs">347<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">SaveAs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.SaveAs" title="Link to this definition">¶</a></dt>348<dd><p>The above two classes provide native dialog windows for saving and loading349files.</p>350</dd></dl>351 352<p><strong>Convenience classes</strong></p>353<p>The below classes are used for creating file/directory windows from scratch.354These do not emulate the native look-and-feel of the platform.</p>355<dl class="py class">356<dt class="sig sig-object py" id="tkinter.filedialog.Directory">357<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">Directory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.Directory" title="Link to this definition">¶</a></dt>358<dd><p>Create a dialog prompting the user to select a directory.</p>359</dd></dl>360 361<div class="admonition note">362<p class="admonition-title">Note</p>363<p>The <em>FileDialog</em> class should be subclassed for custom event364handling and behaviour.</p>365</div>366<dl class="py class">367<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog">368<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">FileDialog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">title</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog" title="Link to this definition">¶</a></dt>369<dd><p>Create a basic file selection dialog.</p>370<dl class="py method">371<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.cancel_command">372<span class="sig-name descname"><span class="pre">cancel_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.cancel_command" title="Link to this definition">¶</a></dt>373<dd><p>Trigger the termination of the dialog window.</p>374</dd></dl>375 376<dl class="py method">377<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.dirs_double_event">378<span class="sig-name descname"><span class="pre">dirs_double_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.dirs_double_event" title="Link to this definition">¶</a></dt>379<dd><p>Event handler for double-click event on directory.</p>380</dd></dl>381 382<dl class="py method">383<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.dirs_select_event">384<span class="sig-name descname"><span class="pre">dirs_select_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.dirs_select_event" title="Link to this definition">¶</a></dt>385<dd><p>Event handler for click event on directory.</p>386</dd></dl>387 388<dl class="py method">389<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.files_double_event">390<span class="sig-name descname"><span class="pre">files_double_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.files_double_event" title="Link to this definition">¶</a></dt>391<dd><p>Event handler for double-click event on file.</p>392</dd></dl>393 394<dl class="py method">395<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.files_select_event">396<span class="sig-name descname"><span class="pre">files_select_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.files_select_event" title="Link to this definition">¶</a></dt>397<dd><p>Event handler for single-click event on file.</p>398</dd></dl>399 400<dl class="py method">401<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.filter_command">402<span class="sig-name descname"><span class="pre">filter_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.filter_command" title="Link to this definition">¶</a></dt>403<dd><p>Filter the files by directory.</p>404</dd></dl>405 406<dl class="py method">407<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.get_filter">408<span class="sig-name descname"><span class="pre">get_filter</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.get_filter" title="Link to this definition">¶</a></dt>409<dd><p>Retrieve the file filter currently in use.</p>410</dd></dl>411 412<dl class="py method">413<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.get_selection">414<span class="sig-name descname"><span class="pre">get_selection</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.get_selection" title="Link to this definition">¶</a></dt>415<dd><p>Retrieve the currently selected item.</p>416</dd></dl>417 418<dl class="py method">419<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.go">420<span class="sig-name descname"><span class="pre">go</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dir_or_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">os.curdir</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pattern</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'*'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.go" title="Link to this definition">¶</a></dt>421<dd><p>Render dialog and start event loop.</p>422</dd></dl>423 424<dl class="py method">425<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.ok_event">426<span class="sig-name descname"><span class="pre">ok_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">event</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.ok_event" title="Link to this definition">¶</a></dt>427<dd><p>Exit dialog returning current selection.</p>428</dd></dl>429 430<dl class="py method">431<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.quit">432<span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">how</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.quit" title="Link to this definition">¶</a></dt>433<dd><p>Exit dialog returning filename, if any.</p>434</dd></dl>435 436<dl class="py method">437<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.set_filter">438<span class="sig-name descname"><span class="pre">set_filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dir</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pat</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.set_filter" title="Link to this definition">¶</a></dt>439<dd><p>Set the file filter.</p>440</dd></dl>441 442<dl class="py method">443<dt class="sig sig-object py" id="tkinter.filedialog.FileDialog.set_selection">444<span class="sig-name descname"><span class="pre">set_selection</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.FileDialog.set_selection" title="Link to this definition">¶</a></dt>445<dd><p>Update the current file selection to <em>file</em>.</p>446</dd></dl>447 448</dd></dl>449 450<dl class="py class">451<dt class="sig sig-object py" id="tkinter.filedialog.LoadFileDialog">452<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">LoadFileDialog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">title</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.LoadFileDialog" title="Link to this definition">¶</a></dt>453<dd><p>A subclass of FileDialog that creates a dialog window for selecting an454existing file.</p>455<dl class="py method">456<dt class="sig sig-object py" id="tkinter.filedialog.LoadFileDialog.ok_command">457<span class="sig-name descname"><span class="pre">ok_command</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.LoadFileDialog.ok_command" title="Link to this definition">¶</a></dt>458<dd><p>Test that a file is provided and that the selection indicates an459already existing file.</p>460</dd></dl>461 462</dd></dl>463 464<dl class="py class">465<dt class="sig sig-object py" id="tkinter.filedialog.SaveFileDialog">466<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.filedialog.</span></span><span class="sig-name descname"><span class="pre">SaveFileDialog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">title</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.SaveFileDialog" title="Link to this definition">¶</a></dt>467<dd><p>A subclass of FileDialog that creates a dialog window for selecting a468destination file.</p>469<dl class="py method">470<dt class="sig sig-object py" id="tkinter.filedialog.SaveFileDialog.ok_command">471<span class="sig-name descname"><span class="pre">ok_command</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.filedialog.SaveFileDialog.ok_command" title="Link to this definition">¶</a></dt>472<dd><p>Test whether or not the selection points to a valid file that is not a473directory. Confirmation is required if an already existing file is474selected.</p>475</dd></dl>476 477</dd></dl>478 479</section>480</section>481<section id="module-tkinter.commondialog">482<span id="tkinter-commondialog-dialog-window-templates"></span><h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.commondialog</span></code> — Dialog window templates<a class="headerlink" href="#module-tkinter.commondialog" title="Link to this heading">¶</a></h2>483<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/tkinter/commondialog.py">Lib/tkinter/commondialog.py</a></p>484<hr class="docutils" />485<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.commondialog</span></code> module provides the <a class="reference internal" href="#tkinter.commondialog.Dialog" title="tkinter.commondialog.Dialog"><code class="xref py py-class docutils literal notranslate"><span class="pre">Dialog</span></code></a> class that486is the base class for dialogs defined in other supporting modules.</p>487<dl class="py class">488<dt class="sig sig-object py" id="tkinter.commondialog.Dialog">489<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">tkinter.commondialog.</span></span><span class="sig-name descname"><span class="pre">Dialog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">master</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.commondialog.Dialog" title="Link to this definition">¶</a></dt>490<dd><dl class="py method">491<dt class="sig sig-object py" id="tkinter.commondialog.Dialog.show">492<span class="sig-name descname"><span class="pre">show</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tkinter.commondialog.Dialog.show" title="Link to this definition">¶</a></dt>493<dd><p>Render the Dialog window.</p>494</dd></dl>495 496</dd></dl>497 498<div class="admonition seealso">499<p class="admonition-title">See also</p>500<p>Modules <a class="reference internal" href="tkinter.messagebox.html#module-tkinter.messagebox" title="tkinter.messagebox: Various types of alert dialogs"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.messagebox</span></code></a>, <a class="reference internal" href="../tutorial/inputoutput.html#tut-files"><span class="std std-ref">Reading and Writing Files</span></a></p>501</div>502</section>503</section>504 505 506 <div class="clearer"></div>507 </div>508 </div>509 </div>510 <div class="sphinxsidebar" role="navigation" aria-label="Main">511 <div class="sphinxsidebarwrapper">512 <div>513 <h3><a href="../contents.html">Table of Contents</a></h3>514 <ul>515<li><a class="reference internal" href="#">Tkinter Dialogs</a><ul>516<li><a class="reference internal" href="#module-tkinter.simpledialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.simpledialog</span></code> — Standard Tkinter input dialogs</a></li>517<li><a class="reference internal" href="#module-tkinter.filedialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.filedialog</span></code> — File selection dialogs</a><ul>518<li><a class="reference internal" href="#native-load-save-dialogs">Native Load/Save Dialogs</a></li>519</ul>520</li>521<li><a class="reference internal" href="#module-tkinter.commondialog"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.commondialog</span></code> — Dialog window templates</a></li>522</ul>523</li>524</ul>525 526 </div>527 <div>528 <h4>Previous topic</h4>529 <p class="topless"><a href="tkinter.font.html"530 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.font</span></code> — Tkinter font wrapper</a></p>531 </div>532 <div>533 <h4>Next topic</h4>534 <p class="topless"><a href="tkinter.messagebox.html"535 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.messagebox</span></code> — Tkinter message prompts</a></p>536 </div>537 <script>538 document.addEventListener('DOMContentLoaded', () => {539 const title = document.querySelector('meta[property="og:title"]').content;540 const elements = document.querySelectorAll('.improvepage');541 const pageurl = window.location.href.split('?')[0];542 elements.forEach(element => {543 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));544 url.searchParams.set('pagetitle', title);545 url.searchParams.set('pageurl', pageurl);546 url.searchParams.set('pagesource', "library/dialog.rst");547 element.href = url.toString();548 });549 });550 </script>551 <div role="note" aria-label="source link">552 <h3>This page</h3>553 <ul class="this-page-menu">554 <li><a href="../bugs.html">Report a bug</a></li>555 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>556 <li>557 <a href="https://github.com/python/cpython/blob/main/Doc/library/dialog.rst?plain=1"558 rel="nofollow">Show source559 </a>560 </li>561 562 </ul>563 </div>564 </div>565<div id="sidebarbutton" title="Collapse sidebar">566<span>«</span>567</div>568 569 </div>570 <div class="clearer"></div>571 </div> 572 <div class="related" role="navigation" aria-label="Related">573 <h3>Navigation</h3>574 <ul>575 <li class="right" style="margin-right: 10px">576 <a href="../genindex.html" title="General Index"577 >index</a></li>578 <li class="right" >579 <a href="../py-modindex.html" title="Python Module Index"580 >modules</a> |</li>581 <li class="right" >582 <a href="tkinter.messagebox.html" title="tkinter.messagebox — Tkinter message prompts"583 >next</a> |</li>584 <li class="right" >585 <a href="tkinter.font.html" title="tkinter.font — Tkinter font wrapper"586 >previous</a> |</li>587 588 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>589 <li><a href="https://www.python.org/">Python</a> »</li>590 <li class="switchers">591 <div class="language_switcher_placeholder"></div>592 <div class="version_switcher_placeholder"></div>593 </li>594 <li>595 596 </li>597 <li id="cpython-language-and-version">598 <a href="../index.html">3.15.0a6 Documentation</a> »599 </li>600 601 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>602 <li class="nav-item nav-item-2"><a href="tk.html" >Graphical user interfaces with Tk</a> »</li>603 <li class="nav-item nav-item-this"><a href="">Tkinter Dialogs</a></li>604 <li class="right">605 606 607 <div class="inline-search" role="search">608 <form class="inline-search" action="../search.html" method="get">609 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">610 <input type="submit" value="Go">611 </form>612 </div>613 |614 </li>615 <li class="right">616<label class="theme-selector-label">617 Theme618 <select class="theme-selector" oninput="activateTheme(this.value)">619 <option value="auto" selected>Auto</option>620 <option value="light">Light</option>621 <option value="dark">Dark</option>622 </select>623</label> |</li>624 625 </ul>626 </div> 627 <div class="footer">628 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.629 <br>630 This page is licensed under the Python Software Foundation License Version 2.631 <br>632 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.633 <br>634 635 See <a href="/license.html">History and License</a> for more information.<br>636 637 638 <br>639 640 The Python Software Foundation is a non-profit corporation.641<a href="https://www.python.org/psf/donations/">Please donate.</a>642<br>643 <br>644 Last updated on Mar 10, 2026 (08:58 UTC).645 646 <a href="/bugs.html">Found a bug</a>?647 648 <br>649 650 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.651 </div>652 653 </body>654</html>