I have completed a script which opens various txt files within a folder path and does calculations on them, currently being set for example:

path = "./folderfileshere"

is there a simple solution to grab a folder path using a gui function similar to that of the browse for folder function in .net

this will than set the path to what the user has chosen

something like this

http://www.microsoft.com/library/media/1033/windowsxp/images/using/setup/tips/advanced/67455-browse-for-folder.gif


Thanks

You can use the tkFileDialog module
http://epydoc.sourceforge.net/stdlib/tkFileDialog-module.html
Example :

# -*- coding: iso-8859-1 -*-
import tkFileDialog
from Tkinter import *

class openDialog(Frame):
    def __init__(self, master=None):
        self.root=master
        self.createWidgets()

    def createWidgets(self):
        """ Create widgets
        """
        self.fFrame = Frame(self.root)

        self.svDir = StringVar()
        self.eDir  = Entry(self.fFrame, width=70, textvariable=self.svDir)
        self.eDir.pack()

        self.bSelDir = Button(self.fFrame, text="askdir")
        self.bSelDir["command"] =  self.getDir
        self.bSelDir.pack()

        self.fFrame.pack()

    def getDir(self):
        self.dir=tkFileDialog.askdirectory()
        self.svDir.set(self.dir)


if __name__ == "__main__":
    root=Tk()
    od = openDialog(root)
    root.mainloop()
This article has been dead for over six months. Start a new discussion instead.