Tkinter dialogs¶
tkinter.simpledialog — Standard Tkinter input dialogs¶
소스 코드: Lib/tkinter/simpledialog.py
The tkinter.simpledialog module contains convenience classes and
functions for creating simple modal dialogs to get a value from the user.
- tkinter.simpledialog.askfloat(title, prompt, **kw)¶
- tkinter.simpledialog.askinteger(title, prompt, **kw)¶
- tkinter.simpledialog.askstring(title, prompt, **kw)¶
위의 세 함수는 사용자에게 원하는 형의 값을 입력하도록 요구하는 대화 상자를 제공합니다.
- class tkinter.simpledialog.Dialog(parent, title=None)¶
사용자 정의 대화 상자의 베이스 클래스.
- body(master)¶
대화 상자의 인터페이스를 구성하고 초기 포커스가 필요한 위젯을 반환하도록 재정의하십시오.
- buttonbox()¶
기본 동작은 OK 와 Cancel 버튼을 추가합니다. 사용자 정의 버튼 레이아웃이 필요하면 재정의하십시오.
- validate()¶
Validate the data entered by the user. Return true if it is valid, in which case the dialog proceeds to
apply(); return false to keep the dialog open. The default implementation always returns true; override it to check the input.
- apply()¶
Process the data entered by the user. Called after
validate()succeeds and just before the dialog is destroyed. The default implementation does nothing; override it to act on or store the result.
- destroy()¶
Destroy the dialog window, clearing the reference to the widget that had the initial focus.
- class tkinter.simpledialog.SimpleDialog(master, text='', buttons=[], default=None, cancel=None, title=None, class_=None)¶
A simple modal dialog that displays the message text above a row of push buttons whose labels are given by buttons, and returns the index of the button the user presses. default is the index of the button activated by the Return key, cancel the index returned when the window is closed through the window manager, title the window title, and class_ the Tk class name of the window.
- go()¶
Display the dialog, wait until the user presses a button or closes the window, and return the index of the chosen button.
tkinter.filedialog — File selection dialogs¶
소스 코드: Lib/tkinter/filedialog.py
The tkinter.filedialog module provides classes and factory functions for
creating file/directory selection windows.
Native load/save dialogs¶
다음 클래스와 함수는 네이티브 모양과 느낌을 동작을 사용자 정의하는 구성 옵션과 결합하는 파일 대화 상자 창을 제공합니다. 다음 키워드 인자는 아래 나열된 클래스와 함수에 적용할 수 있습니다:
parent - 대화 상자를 그 위에 놓을 창title - 창의 제목initialdir - 대화 상자가 시작되는 디렉터리initialfile - 대화 상자를 열 때 선택된 파일filetypes - (label, pattern) 튜플의 시퀀스, ‘*’ 와일드카드가 허용됩니다defaultextension - 파일에 추가할 기본 확장자 (저장 대화 상자)multiple - 참일 때, 여러 항목을 선택할 수 있습니다
정적 팩토리 함수
The below functions when called create a modal, native look-and-feel dialog,
wait for the user’s selection, and return it.
The exact return value depends on the function (see below); when the dialog is
cancelled it is an empty string, an empty tuple, an empty list or None.
- tkinter.filedialog.askopenfile(mode='r', **options)¶
- tkinter.filedialog.askopenfiles(mode='r', **options)¶
Create an
Opendialog.askopenfile()returns the opened file object, orNoneif the dialog is cancelled.askopenfiles()returns a list of the opened file objects, or an empty list if cancelled. The files are opened in mode mode (read-only'r'by default).
- tkinter.filedialog.asksaveasfile(mode='w', **options)¶
Create a
SaveAsdialog and return the opened file object, orNoneif the dialog is cancelled. The file is opened in mode mode ('w'by default).
- tkinter.filedialog.askopenfilename(**options)¶
- tkinter.filedialog.askopenfilenames(**options)¶
Create an
Opendialog.askopenfilename()returns the selected filename as a string, or an empty string if the dialog is cancelled.askopenfilenames()returns a tuple of the selected filenames, or an empty tuple if cancelled.
- tkinter.filedialog.asksaveasfilename(**options)¶
Create a
SaveAsdialog and return the selected filename as a string, or an empty string if the dialog is cancelled.
- tkinter.filedialog.askdirectory(**options)¶
Prompt the user to select a directory, and return its path as a string, or an empty string if the dialog is cancelled. Additional keyword option: mustexist - if true, the user may only select an existing directory (false by default).
- class tkinter.filedialog.Open(master=None, **options)¶
- class tkinter.filedialog.SaveAs(master=None, **options)¶
위의 두 클래스는 파일 저장과 로드를 위한 네이티브 대화 창을 제공합니다.
편의 클래스
아래 클래스는 파일/디렉터리 창을 처음부터 만드는 데 사용됩니다. 이것들은 플랫폼의 네이티브 모양과 느낌을 모방하지 않습니다.
- class tkinter.filedialog.Directory(master=None, **options)¶
사용자에게 디렉터리를 선택하라는 대화 상자를 만듭니다.
참고
FileDialog 클래스는 사용자 정의 이벤트 처리와 동작을 위해 서브 클래싱 되어야 합니다.
- class tkinter.filedialog.FileDialog(master, title=None)¶
기본 파일 선택 대화 상자를 만듭니다.
- cancel_command(event=None)¶
대화 창의 종료를 트리거 합니다.
- dirs_double_event(event)¶
디렉터리에 대한 더블 클릭 이벤트를 위한 이벤트 처리기.
- dirs_select_event(event)¶
디렉터리에 대한 클릭 이벤트를 위한 이벤트 처리기.
- files_double_event(event)¶
파일에 대한 더블 클릭 이벤트를 위한 이벤트 처리기.
- files_select_event(event)¶
파일에 대한 단일 클릭 이벤트를 위한 이벤트 처리기.
- filter_command(event=None)¶
디렉터리로 파일을 필터링합니다.
- get_filter()¶
현재 사용 중인 파일 필터를 가져옵니다.
- get_selection()¶
현재 선택된 항목을 가져옵니다.
- go(dir_or_file=os.curdir, pattern='*', default='', key=None)¶
대화 상자를 렌더링하고 이벤트 루프를 시작합니다.
- ok_event(event)¶
현재 선택을 반환하면서 대화 상자를 종료합니다.
- ok_command()¶
Called when the user confirms the current selection. The base implementation accepts the selection and closes the dialog;
LoadFileDialogandSaveFileDialogoverride it to check the selection first.
- quit(how=None)¶
파일명을 (있다면) 반환하면서 대화 상자를 종료합니다.
- set_filter(dir, pat)¶
파일 필터를 설정합니다.
- set_selection(file)¶
현재 파일 선택을 file로 갱신합니다.
tkinter.commondialog — Dialog window templates¶
소스 코드: Lib/tkinter/commondialog.py
The tkinter.commondialog module provides the Dialog class that
is the base class for dialogs defined in other supporting modules.
tkinter.dialog — Classic Tk dialog boxes¶
Source code: Lib/tkinter/dialog.py
The tkinter.dialog module provides a simple modal dialog box built on
the classic (non-themed) Tk widgets.
- class tkinter.dialog.Dialog(master=None, cnf={}, **kw)¶
Display a modal dialog box built from the classic (non-themed) Tk widgets and wait for the user to press one of its buttons. The options, given through cnf or as keyword arguments, include title (the window title), text (the message), bitmap (an icon,
DIALOG_ICONby default), default (the index of the default button) and strings (the sequence of button labels). After construction, thenumattribute holds the index of the button the user pressed.- destroy()¶
Destroy the dialog window.
더 보기