4

I want to delete all rows whenever i select new directory but it appends when i select new directory.. whenever i select new directory i want all previous rows be deleted and and new rows be inserted .?

def dirNmeFrmBtn(do=' '):
if do == ' ':
    path =  tkFileDialog.askdirectory()
else:
    path =  do

processStatus('Error','No Directory Selected')
if os.path.isdir(path):
    oldDir = curDir.get()
    curDir.delete(0,last=END)
    curDir.insert(1,path)
    processStatus('Done','Directory Selected :  ' + path)

    files = os.listdir(path)
    i = 1
    for x in files:


            files = file.file(path+'/'+x)
            if os.path.isfile(path+'/'+x):
                t.insert("",i,text=x,values=(files.type, files.size,files.modi),tags=('files',))

            elif os.path.isdir(path+'/'+x):
                t.insert("",i,text=x,values=('Dir', files.size,files.modi),tags=('dir',))

            else:
                t.insert("",i,text=x,values=('unknown', files.size,files.modi),tags=('unknown',))

    i += 1
    t.bind("<Double-1>",updateTree)
    t.pack()
Brian
  • 12,145
  • 20
  • 90
  • 153
Samundra Khatri
  • 997
  • 1
  • 9
  • 18

1 Answers1

7

All you have to do to clear the rows of a Treeview is use the following lines:

for row in treeview.get_children():
    treeview.delete(row)

Hope this helps!

(Actually a repeat of this)

Community
  • 1
  • 1
noahbkim
  • 528
  • 2
  • 13