Dan Alexander
Dan Alexander

Reputation: 2072

Display directories in tkinter

I am developing a program which has it's own special folder with sub folders and I want to know if there is a way of displaying all the folders and files in my window like my own custom file browser but I don't mean like the tkinter filedialog.

Upvotes: 2

Views: 3950

Answers (2)

Donal Fellows
Donal Fellows

Reputation: 137587

Don't want to use the built-in versions of things and instead desire to build it yourself to get extra control? Consider using the Treeview; you'll have to provide code to populate the contents, but you can do a multi-column view easily with it where the first column is a hierarchic tree. That's the sort of thing you want when doing an Explorer-like interface. (If you were using the Tcl bindings to Tk, I'd point you to a specific script of interest in the standard widget demonstrator that shows the basics of doing this sort of thing — the “directory browser tree” under “Listboxes and Trees” — but I don't know the Python equivalents well enough to do the same.)

Upvotes: 2

FabienAndre
FabienAndre

Reputation: 4604

Tkinter does not provides this kind of widget. However, Tix (Tk Interface Extension) has this kind of widgets: tix.DirList, tix.FileSelectBox... (see tix documentation for pictures). In your case, I woud use tix.ExFileSelectBox.

import tkinter.tix
root = tkinter.tix.Tk()

fs = tkinter.tix.ExFileSelectBox(root, directory="/the/folder/your/want")
fs.pack()

Upvotes: 0

Related Questions