Tkinter ダイアログ¶
tkinter.simpledialog
--- 標準 Tkinter 入力ダイアログ¶
ソースコード: Lib/tkinter/simpledialog.py
tkinter.simpledialog
モジュールは、ユーザーに値を入力させる単純なモーダルダイアログを作成するための便利なクラスや関数を含んでいます。
tkinter.filedialog
--- ファイル選択ダイアログ¶
ソースコード: Lib/tkinter/filedialog.py
The tkinter.filedialog
module provides classes and factory functions for
creating file/directory selection windows.
ネイティブの読み込み/保存ダイアログ¶
下記のクラスは、振る舞いをカスタマイズできる設定オプション付きの、ネイティブルック&フィールと統合したファイルダイアログを提供します。以下のキーワード引数は、下記で列挙するクラスや関数に適用できます。
parent - ダイアログをその上に表示するウィンドウtitle - ウィンドウのタイトルinitialdir - 最初に表示するディレクトリinitialfile - ダイアログを表示した際に選択するファイルfiletypes - (ラベル, パターン) のタプルからなるシーケンスで、'*' ワイルドカードが利用できますdefaultextension - ファイルに追加するデフォルトの拡張子 (保存ダイアログ向け)multiple - 真の場合、複数要素の選択を許可します
静的なファクトリ関数
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 None
to the
caller.
- tkinter.filedialog.askopenfile(mode='r', **options)¶
- tkinter.filedialog.askopenfiles(mode='r', **options)¶
The above two functions create an
Open
dialog and return the opened file object(s) in read-only mode.
- tkinter.filedialog.asksaveasfile(mode='w', **options)¶
Create a
SaveAs
dialog and return a file object opened in write-only mode.
- tkinter.filedialog.askopenfilename(**options)¶
- tkinter.filedialog.askopenfilenames(**options)¶
The above two functions create an
Open
dialog and return the selected filename(s) that correspond to existing file(s).
- tkinter.filedialog.asksaveasfilename(**options)¶
Create a
SaveAs
dialog and return the selected filename.
- tkinter.filedialog.askdirectory(**options)¶
- Prompt user to select a directory.Additional keyword option:mustexist - determines if selection must be an existing directory.
- class tkinter.filedialog.Open(master=None, **options)¶
- class tkinter.filedialog.SaveAs(master=None, **options)¶
The above two classes provide native dialog windows for saving and loading files.
便利なクラス
The below classes are used for creating file/directory windows from scratch. These do not emulate the native look-and-feel of the platform.
- class tkinter.filedialog.Directory(master=None, **options)¶
Create a dialog prompting the user to select a directory.
注釈
The FileDialog class should be subclassed for custom event handling and behaviour.
- class tkinter.filedialog.FileDialog(master, title=None)¶
Create a basic file selection dialog.
- cancel_command(event=None)¶
Trigger the termination of the dialog window.
- dirs_double_event(event)¶
Event handler for double-click event on directory.
- dirs_select_event(event)¶
Event handler for click event on directory.
- files_double_event(event)¶
Event handler for double-click event on file.
- files_select_event(event)¶
Event handler for single-click event on file.
- filter_command(event=None)¶
Filter the files by directory.
- get_filter()¶
Retrieve the file filter currently in use.
- get_selection()¶
Retrieve the currently selected item.
- go(dir_or_file=os.curdir, pattern='*', default='', key=None)¶
Render dialog and start event loop.
- ok_event(event)¶
Exit dialog returning current selection.
- quit(how=None)¶
Exit dialog returning filename, if any.
- set_filter(dir, pat)¶
Set the file filter.
- set_selection(file)¶
Update the current file selection to file.
- class tkinter.filedialog.LoadFileDialog(master, title=None)¶
A subclass of FileDialog that creates a dialog window for selecting an existing file.
- ok_command()¶
Test that a file is provided and that the selection indicates an already existing file.
- class tkinter.filedialog.SaveFileDialog(master, title=None)¶
A subclass of FileDialog that creates a dialog window for selecting a destination file.
- ok_command()¶
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.
tkinter.commondialog
--- Dialog window templates¶
Source code: Lib/tkinter/commondialog.py
The tkinter.commondialog
module provides the Dialog
class that
is the base class for dialogs defined in other supporting modules.
- class tkinter.commondialog.Dialog(master=None, **options)¶
- show(color=None, **options)¶
Render the Dialog window.
参考
Modules tkinter.messagebox
, ファイルを読み書きする