I am making a GUI which will copy folder or file from source to destination.I need to make Tree structure of Directory with checkbox to browse file.I refered this How to create a tree view with checkboxes in Python but i did't find logic to create whole folder . Please help me to solve this issue.
from tkinter import tix
import os
i = 0
class View(object):
def __init__(self, root,path):
self.root = root
self.path = path
self.makeCheckList(self.path)
def makeCheckList(self,path1):
global i
self.cl = tix.CheckList(self.root, browsecmd=self.selectItem)
self.cl.pack(fill='both',expand="yes")
self.cl.hlist.add("CL1", text=path1)
self.cl.setstatus("CL1", "off")
self.check(path1)
self.cl.autosetmode()
def selectItem(self, item):
print (item, self.cl.getstatus(item))
def check(self,path1):
global i
self.path1 = path1
file = os.listdir(path1)
for p in file:
#print(p)
full_path = path1 +"\\"+ p
val = "CL1.Item1"
if os.path.isdir(full_path) != True :
self.cl.hlist.add("CL1.Item"+ str(i), text=p)
self.cl.setstatus("CL1.Item"+str(i), "off")
i = i + 1
self.dir(path1)
def dir(self,path1):
global i
self.path1 = path1
file = os.listdir(path1)
for folder in file:
full_path = path1 +"\\"+ folder
if os.path.isdir(full_path) == True :
self.cl.hlist.add("CL1.Item"+str(i), text=folder)
self.cl.setstatus("CL1.Item"+str(i), "off")
i = i + 1
#self.dir(full_path)
def main():
root = tix.Tk()
root.geometry("800x400")
view = View(root,"C:\\")
root.update()
root.mainloop()
if __name__ == '__main__':
main()
My logic is not correct here.I want a recursive function which will create whole directory