Package: tkfilebrowser
tkfilebrowsertkfilebrowser is an alternative to tkinter.filedialog that allows the
user to select files or directories. The GUI is written with tkinter but
the look is closer to GTK and the application uses GTK bookmarks (the
one displayed in nautilus or thunar for instance). This filebrowser
supports new directory creation and filtype filtering.This module contains a generalFileBrowserclass which implements the
filebrowser and the following functions, similar to the one in filedialog:askopenfilenamethat allow the selection of a single fileaskopenfilenamesthat allow the selection of multiple filesaskopendirnamethat allow the selection a single folderaskopendirnamesthat allow the selection of multiple foldersasksaveasfilenamethat returns a single filename and give a warning if the file already existsThe documentation is also available here:https://tkfilebrowser.readthedocs.ioTable of ContentstkfilebrowserRequirementsInstallationDocumentationChangelogExampleRequirementsLinux or WindowsPython 2.7 or 3.xAnd the python packages:tkinter (included in the python distribution for Windows)psutilbabelpywin32(Windows only)pillow(only if tkinter.TkVersion < 8.6)InstallationUbuntu: use the PPAppa:j-4321-i/ppa$ sudo add-apt-repository ppa:j-4321-i/ppa
$ sudo apt-get update
$ sudo apt-get install python(3)-tkfilebrowserArchlinux:the package is available onAURWith pip:$ pip install tkfilebrowserDocumentationOptional keywords arguments common to each functionparent: parent windowtitle: the title of the filebrowser windowinitialdir: directory whose content is initially displayedinitialfile: initially selected item (just the name, not the full path)filetypes list: [(“name”, “*.ext1|*.ext2|..”), …]
only the files of given filetype will be displayed,
e.g. to allow the user to switch between displaying only PNG or JPG
pictures or dispalying all files:
filtypes=[(“Pictures”, “*.png|*.PNG|*.jpg|*.JPG’), (“All files”, “*”)]okbuttontext: text displayed on the validate button, if None, the
default text corresponding to the mode is used (either “Open” or “Save”)cancelbuttontext: text displayed on the button that cancels the
selection.foldercreation: enable the user to create new folders if True (default)askopendirnameAllow the user to choose a single directory. The absolute path of the
chosen directory is returned. If the user cancels, an empty string is
returned.askopendirnamesAllow the user to choose multiple directories. A tuple containing the absolute
path of the chosen directories is returned. If the user cancels,
an empty tuple is returned.askopenfilenameAllow the user to choose a single file. The absolute path of the
chosen file is returned. If the user cancels, an empty string is
returned.askopenfilenamesAllow the user to choose multiple files. A tuple containing the absolute
path of the chosen files is returned. If the user cancels,
an empty tuple is returned.asksaveasfilenameAllow the user to choose a file path. The file may not exist but
the path to its directory does. If the file already exists, the user
is asked to confirm its replacement.Additional option:defaultext: extension added to filename if none is given (default is none)Changelogtkfilebrowser 2.3.2Show networked drives on WindowsFix click on root button in path bartkfilebrowser 2.3.1Fix path bar navigation in Linuxtkfilebrowser 2.3.0Make package compatible with WindowsSet initial focus on entry in save modetkfilebrowser 2.2.6No longer reset path bar when clicking on a path buttonFix bug caused by broken linkstkfilebrowser 2.2.5Add compatibility with Tk < 8.6.0 (requires PIL.ImageTk)Add desktop icon in shortcutsFix handling of spaces in bookmarksFix bug due to spaces in recent file namestkfilebrowser 2.2.4Fix bug in desktop folder identificationtkfilebrowser 2.2.3Fix FileNotFoundError if initialdir does not existAdd Desktop in shortcuts (if found)Improve filetype filteringtkfilebrowser 2.2.2Fix ValueError in after_cancel with Python 3.6.5tkfilebrowser 2.2.1Fix __main__.py for python 2tkfilebrowser 2.2.0Use babel instead of locale in order not to change the locale globallySpeed up (a little) folder content displayImprove example: add comparison with default dialogsAdd select all on Ctrl+A if multiple selection is enabledDisable folder creation button if the user does not have write accessImprove extension management in save modetkfilebrowser 2.1.1Fix error if LOCAL_PATH does not exists or is not writtabletkfilebrowser 2.1.0Add compatibility with tkinter.filedialog keywords ‘master’ and ‘defaultextension’Change look of filetype selectorFix bugs when navigating without displaying hidden filesFix color alternance bug when hiding hidden filesFix setup.pyHide suggestion drop-down when nothing matches anymoretkfilebrowser 2.0.0Change package name to tkfilebrowser to respect PEP 8Display error message when an issue occurs during folder creationCycle only through folders with key browsing in “opendir” modeComplete only with folder names in “opendir” modeFix bug: grey/white color alternance not always respectedAdd __main__.py with an exampleAdd “Recent files” shortcutMake the text of the validate and cancel buttons customizableAdd possibility to disable new folder creationAdd python 2 supportAdd horizontal scrollbartkFileBrowser 1.1.2Add tooltips to display the full path of the shortcut if the mouse stays
long enough over it.Fix bug: style of browser treeview applied to parenttkFileBrowser 1.1.1Fix bug: key browsing did not work with capital lettersAdd specific icons for symlinksAdd handling of symlinks, the real path is returned instead of the link pathtkFileBrowser 1.1.0Fix bug concerning the initialfile argumentAdd column sorting (by name, size, modification date)tkFileBrowser 1.0.1Set default filebrowser parent to None as for the usual filedialogs and messageboxes.tkFileBrowser 1.0.0Initial versionExampletry:importtkinterastkimporttkinter.ttkasttkfromtkinterimportfiledialogexceptImportError:importTkinterastkimportttkimporttkFileDialogasfiledialogfromtkfilebrowserimportaskopendirname,askopenfilenames,asksaveasfilenameroot=tk.Tk()style=ttk.Style(root)style.theme_use("clam")defc_open_file_old():rep=filedialog.askopenfilenames(parent=root,initialdir='/',initialfile='tmp',filetypes=[("PNG","*.png"),("JPEG","*.jpg"),("All files","*")])print(rep)defc_open_dir_old():rep=filedialog.askdirectory(parent=root,initialdir='/tmp')print(rep)defc_save_old():rep=filedialog.asksaveasfilename(parent=root,defaultextension=".png",initialdir='/tmp',initialfile='image.png',filetypes=[("PNG","*.png"),("JPEG","*.jpg"),("All files","*")])print(rep)defc_open_file():rep=askopenfilenames(parent=root,initialdir='/',initialfile='tmp',filetypes=[("Pictures","*.png|*.jpg|*.JPG"),("All files","*")])print(rep)defc_open_dir():rep=askopendirname(parent=root,initialdir='/',initialfile='tmp')print(rep)defc_save():rep=asksaveasfilename(parent=root,defaultext=".png",initialdir='/tmp',initialfile='image.png',filetypes=[("Pictures","*.png|*.jpg|*.JPG"),("All files","*")])print(rep)ttk.Label(root,text='Default dialogs').grid(row=0,column=0,padx=4,pady=4,sticky='ew')ttk.Label(root,text='tkfilebrowser dialogs').grid(row=0,column=1,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Open files",command=c_open_file_old).grid(row=1,column=0,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Open folder",command=c_open_dir_old).grid(row=2,column=0,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Save file",command=c_save_old).grid(row=3,column=0,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Open files",command=c_open_file).grid(row=1,column=1,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Open folder",command=c_open_dir).grid(row=2,column=1,padx=4,pady=4,sticky='ew')ttk.Button(root,text="Save file",command=c_save).grid(row=3,column=1,padx=4,pady=4,sticky='ew')root.mainloop()