python - Having dynamic tkinter label without StringVar -
i'm pretty new python , trying dynamically add buttons on gui corresponding label on frame, works. however, having problem afterwards when click button open directory selector, label not update based on new path because textvariable takes in stringvar while using dictionary keep track of dynamically created buttons , paths (which not stringvar). unless if there way typecast normal strings stringvar?
i hope explained enough understand.
here's horribly written code i'm pretty trying see how works. basically, program supposed take in starting directory, , other directories starting directory copied to. didn't actual saving part though.
from tkinter import * dirid = [] dirmap = {} diramt = 0 def getdirname(): dirname1.set(filedialog.askdirectory()) def getsavedirname(event): dirmap[event.widget] = filedialog.askdirectory() def strtostringvar(name): temp = stringvar() temp.set(name) return temp def adddir(): global diramt global dirid b = button(mainframe, text = "directory" + str(diramt)) dirmap[b] = filedialog.askdirectory() b.bind("<button-1>", getsavedirname) b.place(x=10,y=(100+(60*diramt))) name = stringvar() name.set(dirmap[b]) l = label(mainframe, textvariable = name) l.place(x=10,y=(130+(60*diramt))) dirid.append(b) diramt = diramt + 1 update(self) def save(): in range (0,diramt): print (dirmap[dirid[i]]) root=tk() root.title("file copier") mainframe = frame(root, width = 600, height = 500) mainframe.pack() #variables dirname1 = stringvar() #gui getdirlabel = label(mainframe, text="directory copy:") getdirbutton = button(mainframe, text = "select directory", command = getdirname)#button choosing directory dirgetpathlabel = label(mainframe, textvariable=dirname1)#label chosen directory savetolabel = label(mainframe, text="directories copy to:") adddirbtnbutton = button(mainframe, text = "add more directories", command = adddir)#button adding directory savebutton = button(mainframe, text = "save", command = save) getdirlabel.place(x = 0, y = 10) getdirbutton.place(x = 100, y=8) dirgetpathlabel.place(x = 5, y = 45) savetolabel.place(x = 0, y = 70) adddirbtnbutton.place(x = 130, y = 68) savebutton.place(x = 300, y = 68) root.mainloop()
Comments
Post a Comment