0

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.

3
Contributors
2
Replies
16
Views
4 Years
Discussion Span
Last Post by vegaseat
1

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()

Edited by vegaseat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.