# Use The Return Variable Of A Button-command

**URL:** https://forum.highend3d.com/t/use-the-return-variable-of-a-button-command/48743
**Category:** Maya
**Tags:** python
**Created:** [June 29, 2009, 5:30pm UTC](https://forum.highend3d.com/t/use-the-return-variable-of-a-button-command/48743 "2009-06-29T17:30:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![brueggz](https://forum.highend3d.com/user_avatar/forum.highend3d.com/brueggz/32/196_2.png) [@brueggz](https://forum.highend3d.com/u/brueggz)
#### Post date: [June 29, 2009, 5:30pm UTC](https://forum.highend3d.com/t/use-the-return-variable-of-a-button-command/48743/1 "2009-06-29T17:30:38Z")

</div>

Guys you have to help me, I'm completely lost.  
I have a window, with an Entry, a button and a textfield. When I push the load-Button and pick a file, I want the resulting filename to be displayed in the Entry.  
I searched long time, but I seem to be too dumb to find.

I mean, I think it is easy to do with classes, but why should I need a class for this?!

By the way: If you start this, the file open dialog displays even without pushing the load button and won't start, if pushed. Don't know about this problem too. ![]()

CODE  
from Tkinter import \*  
from tkFileDialog import askopenfile

wwidth=300  
wheight=300

def load():  
&nbsp;&nbsp;&nbsp;&nbsp;file=askopenfile(mode='r')  
&nbsp;&nbsp;&nbsp;&nbsp;filepath = str(file)  
&nbsp;&nbsp;&nbsp;&nbsp;return filepath

app = Tk()

topframe = Frame(width=wwidth, height=wheight/10)  
topframe.pack()  
botframe = Frame(width=wwidth, height=wheight/10\*9)  
botframe.pack()

btnLoad = Button(app, text="Load nuke file!", command=load())  
btnLoad.pack()  
btnLoad.place(x=375, y=2)

namefield = Entry(app, text="test", width=60)  
namefield.insert(END,"hi")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;### INSTEAD OF hi I WANT THE FILEPATH HERE  
namefield.pack()  
namefield.place(x=5, y=2)

app.columnconfigure(0, weight=5)  
app.columnconfigure(1, weight=1)

infofield = Text(botframe)  
infofield.pack()

app.protocol("WM\_DELETE\_WINDOW", app.quit)  
app.mainloop()  
app.destroy()

---

<div class="post-metadata">

### Author: ![brueggz](https://forum.highend3d.com/user_avatar/forum.highend3d.com/brueggz/32/196_2.png) [@brueggz](https://forum.highend3d.com/u/brueggz)
#### Post date: [July 1, 2009, 11:16am UTC](https://forum.highend3d.com/t/use-the-return-variable-of-a-button-command/48743/2 "2009-07-01T11:16:56Z")

</div>

I figured it out.  
I just insert the filepath to the entry in the load function. And If I call the load function without parentheses, the function only starts, when the button is pushed.
