Tkinter 對話框?

tkinter.simpledialog --- 標(biāo)準(zhǔn) Tkinter 輸入對話框?

源碼: Lib/tkinter/simpledialog.py


tkinter.simpledialog 模塊包含了一些便捷類和函數(shù),用于創(chuàng)建簡單的模態(tài)對話框,從用戶那里讀取一個值。

tkinter.simpledialog.askfloat(title, prompt, **kw)?
tkinter.simpledialog.askinteger(title, prompt, **kw)?
tkinter.simpledialog.askstring(title, prompt, **kw)?

以上三個函數(shù)提供給用戶輸入期望值的類型的對話框.

class tkinter.simpledialog.Dialog(parent, title=None)?

自定義對話框的基類.

body(master)?

可以覆蓋,用于構(gòu)建對話框的界面,并返回初始焦點所在的部件。

buttonbox()?

加入 OK 和 Cancel 按鈕的默認(rèn)行為. 重寫自定義按鈕布局.

tkinter.filedialog --- 文件選擇對話框.?

源碼: Lib/tkinter/filedialog.py


tkinter.filedialog 模塊提供了用于創(chuàng)建文件/目錄選擇窗口的類和工廠函數(shù)。

原生的載入/保存對話框.?

以下類和函數(shù)提供了文件對話窗口,這些窗口帶有原生外觀,具備可定制行為的配置項。這些關(guān)鍵字參數(shù)適用于下列類和函數(shù):

parent —— 對話框下方的窗口
title —— 窗口的標(biāo)題
initialdir —— 對話框的啟動目錄
initialfile —— 打開對話框時選中的文件
filetypes —— (標(biāo)簽,匹配模式)元組構(gòu)成的列表,允許使用 “*” 通配符
defaultextension —— 默認(rèn)的擴(kuò)展名,用于加到文件名后面(保存對話框)。
multiple —— 為 True 則允許多選

** 靜態(tài)工廠函數(shù) **

調(diào)用以下函數(shù)時,會創(chuàng)建一個模態(tài)的、原生外觀的對話框,等待用戶選取,然后將選中值或 None 返回給調(diào)用者。

tkinter.filedialog.askopenfile(mode='r', **options)?
tkinter.filedialog.askopenfiles(mode='r', **options)?

上述兩個函數(shù)創(chuàng)建了 Open 對話框,并返回一個只讀模式打開的文件對象。

tkinter.filedialog.asksaveasfile(mode='w', **options)?

創(chuàng)建 SaveAs 對話框并返回一個寫入模式打開的文件對象。

tkinter.filedialog.askopenfilename(**options)?
tkinter.filedialog.askopenfilenames(**options)?

以上兩個函數(shù)創(chuàng)建了 Open 對話框,并返回選中的文件名,對應(yīng)著已存在的文件。

tkinter.filedialog.asksaveasfilename(**options)?

創(chuàng)建 SaveAs 對話框,并返回選中的文件名。

tkinter.filedialog.askdirectory(**options)?
提示用戶選擇一個目錄.
其他關(guān)鍵字參數(shù):
mustexist —— 確定是否必須為已存在的目錄。
class tkinter.filedialog.Open(master=None, **options)?
class tkinter.filedialog.SaveAs(master=None, **options)?

上述兩個類提供了用于保存和加載文件的原生對話窗口。

** 便捷類 **

以下類用于從頭開始創(chuàng)建文件/目錄窗口。不會模仿當(dāng)前系統(tǒng)的原生外觀。

class tkinter.filedialog.Directory(master=None, **options)?

創(chuàng)建對話框,提示用戶選擇一個目錄。

備注

為了實現(xiàn)自定義的事件處理和行為,應(yīng)繼承 FileDialog 類。

class tkinter.filedialog.FileDialog(master, title=None)?

創(chuàng)建一個簡單的文件選擇對話框。

cancel_command(event=None)?

觸發(fā)對話窗口的終止。

dirs_double_event(event)?

目錄雙擊事件的處理程序。

dirs_select_event(event)?

目錄單擊事件的處理程序。

files_double_event(event)?

文件雙擊事件的處理程序。

files_select_event(event)?

文件單擊事件的處理程序。

filter_command(event=None)?

按目錄篩選文件。

get_filter()?

獲取當(dāng)前使用的文件篩選器。

get_selection()?

獲取當(dāng)前選中項。

go(dir_or_file=os.curdir, pattern='*', default='', key=None)?

顯示對話框并啟動事件循環(huán)。

ok_event(event)?

退出對話框并返回當(dāng)前選中項。

quit(how=None)?

退出對話框并返回文件名。

set_filter(dir, pat)?

設(shè)置文件篩選器。

set_selection(file)?

將當(dāng)前選中文件更新為 file。

class tkinter.filedialog.LoadFileDialog(master, title=None)?

FileDialog 的一個子類,創(chuàng)建用于選取已有文件的對話窗口。

ok_command()?

檢測有否給出文件,以及選中的文件是否存在。

class tkinter.filedialog.SaveFileDialog(master, title=None)?

FileDialog 的一個子類,創(chuàng)建用于選擇目標(biāo)文件的對話窗口。

ok_command()?

檢測選中文件是否為目錄。如果選中了已存在文件,則需要用戶進(jìn)行確認(rèn)。

tkinter.commondialog --- 對話窗口模板?

源碼: : source:Lib/tkinter/commondialog.py


tkinter.commondialog 模塊提供了 Dialog 類,是其他模塊定義的對話框的基類。

class tkinter.commondialog.Dialog(master=None, **options)?
show(color=None, **options)?

顯示對話窗口。