Jul-10-2018, 09:35 AM
With below code, the label of directory path doesn't be refreshed correctly after I change the directory with "Ctrl+o".
E.g. When you change it to "C:\", you can see the new label is displayed on old label. How to refresh it to show the new label only?
I searched on the internet for 2 dys, no matter update(), destroy() or anything working in my Python v3.6.5.
E.g. When you change it to "C:\", you can see the new label is displayed on old label. How to refresh it to show the new label only?
I searched on the internet for 2 dys, no matter update(), destroy() or anything working in my Python v3.6.5.
import tkinter import tkinter.filedialog import os class fileData: def __init__(self): self.targetDir = "./" self.mainWin = tkinter.Tk() def reportShow(self): ln1 = 2 tkinter.Label(self.mainWin, text = " Target ",justify = tkinter.LEFT).grid(row = ln1, column =0) absPath = os.path.abspath(self.targetDir) if len(absPath) > 40: absPath = ' ...%s' % absPath[-37:] tkinter.Label(self.mainWin, text = absPath, background='white').grid(row = ln1, column = 1, columnspan = 3) def chooseFolder(): #This is where we lauch the directory change bar filesData.targetDir = tkinter.filedialog.askdirectory(title = "Choose the target directory", initialdir=filesData.targetDir) filesData.reportShow() def showMain(): mainWin = filesData.mainWin winSize = 360 mainWin.geometry('%dx%d+%d+%d' % (winSize, winSize, (mainWin.winfo_screenwidth()-winSize)/2, (mainWin.winfo_screenheight()-winSize)/2)) #The size and position of the main window mainWin.minsize(winSize,winSize) mainWin.bind('<Control-o>',lambda event: chooseFolder()) filesData.reportShow() mainWin.mainloop() filesData = fileData() if __name__=="__main__": showMain()