Reputation: 553
How can I create a snippet of code that will create a Tkinter Button widget that opens a tkFileDialog.askopenfilename() window, and when you click the "Open" button in the window, make it get the filename as a string, and insert it into an entry.
Here is what I have.
iconEntry = Entry(iconRow)
iconEntry.pack()
def getFileName()
fileName = tkFileDialog.askopenfilename()
iconEntry.insert(0, fileName)
iconButton = Button(iconRow, text="Browse", command=getFileName)
iconButton.pack(side=RIGHT)
Upvotes: 2
Views: 2553
Reputation: 553
I've got it myself.
root = Tk()
def getFIleName(varName, entryName):
varName = tkFileDialog.askopenfilename()
entryName.insert(0, varName)
iconButton = Button(root, text="Browse", command=(lambda: getImageName(campIcon, iconEntry)))
iconButton.pack()
Upvotes: 4