Hello,

I'm using a askdialog box from tkinter with a form. My problem is when I use "print" or "return" to get the selected directory it prints it to the terminal (if open) and I would like it to print to an Entry textbox. For example:

from Tkinter import *
from tkFileDialog import askdirectory

root = Tk()

e1 = Entry(root)

def browser():
dir1 = askdirectory(title="Select A Folder", mustexist=1)
if len(dir1) > 0:
	print dir1    ###<----------I would like this "dir1" to print into the "e1" Entry above

Button(root, text='Browse', command=browser)

root.mainloop()

I feel like this should be pretty easy but can't seem a way to figure it out. I'm new to Python and taking the learn-as-I-go approach. Any help would be much appreciated.

- RagS

Here is one way to do this ...

from Tkinter import *
from tkFileDialog import askdirectory

def browser():
    dir1 = askdirectory(title="Select A Folder", mustexist=1)
    if len(dir1):
        #print dir1
        e1.insert(0, dir1)

root = Tk()

e1 = Entry(root)
e1.pack()
b1 = Button(root, text='Browse', command=browser)
b1.pack()

root.mainloop()

Thanks you guys for such a quick response. It totally worked!!! I couldn't get the insert() to work but I'm sure it was just a mistake on my end. Setting the control variable and using get() and set() did the trick. If only all forums worked this well...

- RagS

This question has already been answered. Start a new discussion instead.