I'm trying to make my python program more accessible with a minimal GUI with Tkinter grid.
I've created a class that creates a button that asks for a directory to be chosen. This works as it should. However, I want the path of the directory to be mirrored in a row below the button.
class dir_choice:
def __init__(self, master, text, prow, pcol):
self.dir_button = Button(master, text = text, command = self.askdir)
self.dir_button.grid(row = prow, column = pcol)
self.feedb = Label(master, text = "text")
self.feedb.grid(row = prow+1, column = pcol)
def askdir(self):
name = askdirectory() #from tkFileDialog
return name
In use:
dir1 = dir_choice(root, "FOLDER 1", 3, 2)
Instead of text = "text" I want to have something like "C:/user/A/B/C" to be shown below the button if that directory is chosen.
I think I am not correct assuming that this is in the name variable or if it is, I would need to define it differently. So my question is how I can access the value of the askdirectory() function and how I can push that value to the feedb label.
self.dir_buttonandself.feedbare None by definition. The reason is thatgridreturns None. Don't chain grid like this. Call it in e separate line, i.e.self.dir_button.grid(...).