kbk
kbk

Reputation: 605

Entering value to entry widget tkinter

How do i set value to a entry widget of tkinter ?

Label (text='Directory').grid(row=1,column=0)
E2 = Entry(root, width=20)
E2.grid(row=1,column=1)
# Browse Button
blackbutton = Button(root, text="Browse", fg="black", command=sel_Browse)
blackbutton.grid(row=1,column=2)

And in the function i have the directory in

def sel_Browse():
    global filename
    filename = filedialog.askdirectory()

My question is how to five the file name to display in the E2 ?

Thanks, Brijesh

Upvotes: 0

Views: 1255

Answers (1)

A. Rodas
A. Rodas

Reputation: 20689

You only have to clear the content of the widget and insert the new text:

def sel_Browse():
    global filename, E2
    filename = filedialog.askdirectory()
    E2.delete(0, END)
    E2.insert(0, filename)

Alternatively, you can also bind the entry widget with a StringVar, but I think for your purpose this is simpler

Upvotes: 4

Related Questions