how can i add data to a label that i have and keep updating it based on the folder selected

here my code so far

def listDir():

    dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select the file you would like to scan')

    myvar.set('Current Folder Selected is: ') 

    label = Label(root, width = 30, height = 10, textvariable = myvar)

want to add the the dirname variable after current folder selected is: and keep it updated based on variable changing.

You can use something like this:
myvar.set("Current Folder Selected is: {}".format(dirname))

Had to test this ...

try:
    # for Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd


def list_dir():
    dirname = tkfd.askdirectory(parent=root, initialdir="/",
        title='Please select a folder/directory')
    root.title(dirname)  # test only
    myvar.set('Current Folder Selected is: ' + dirname)


root = tk.Tk()

myvar = tk.StringVar()
myvar.set('-----------')
label = tk.Label(root, textvariable=myvar, width=40, bg='yellow')
label.pack(side='left')
button = tk.Button(root, text=" Get Folder ", command=list_dir)
button.pack()

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.