How to get a return from Button?

Muddy Coder cosmo_general at
Tue Feb 10 21:21:19 CET 2009

Hi Folks,

I want to use a Button to trigger askopenfilename() dialog, then I can
select a file. My short code is below:

def select_file():
	filenam = askopenfilename(title='Get the file:')
       return filenam

root = Tk()
Button(root, text='Select a file', command=select_file).pack()

My goal is to get the path of filenam, but the function select_file()
has nowhere to return what it selected. Can anybody help me out? I
consulted the book of Programming Python, but found no demo in this
regard. If the function has no return, command=blabla will work
nicely. I am lost in the scope.


Muddy Coder

More information about the Python-list mailing list