The only real material I have found to help me with this is this SO post and it has gotten me to this point.
I am trying to basically get the user to click the "Browse" button, select a directory when the tkFileDialog.askdirectory
window appears, and when the user selects the appropriate directory - the output is placed inside a Tkinter Entry widget.
Below is the code I am using currently. Right now, it throws a NameError: global name 'var' is not defined
when submitting a directory within the tkFileDialog.askdirectory
window.
I am still learning Python, slowly, and decided that I would try and use OOP. Hence why I am getting really confused right now and the code is messy / hacky.
class MainMenuFrames:
def __init__(self, master):
self.TitleFrame = ttk.Frame(master)
self.OptionsLabelFrame = ttk.LabelFrame(master, text="Options")
self.TitleFrame.pack(side=TOP,
fill="both",
expand=True)
self.OptionsLabelFrame.pack(padx=OptionFramePadding,
pady=OptionFramePadding)
class OptionsContent:
def __init__(self, bottomframe):
def askdirectory():
dirname = tkFileDialog.askdirectory(**self.dir_opt)
if dirname:
var.set(dirname)
return var
self.dir_opt = options = {}
options["initialdir"] = "C:\\"
options["mustexist"] = False
options["parent"] = root
def UserFileInput(status):
text = status
var = StringVar(root)
var.set(text)
w = Entry(bottomframe, width=27, textvariable=var)
w.grid(row=1, column=2, padx=(5, 5), columnspan=2, sticky=E)
return w, var
SVNPathEntry = UserFileInput("")
SVNBrowseButton = ttk.Button(bottomframe,
text="Browse...",
command=askdirectory)
SVNBrowseButton.grid(row=2, column=3, padx=(0, 5), sticky=E)
MainMenu = MainMenuFrames(root)
Title = TitleLabel(MainMenu.TitleFrame)
Options = OptionsContent(MainMenu.OptionsLabelFrame)
Error in question is within the if statement var.set(dirname)