Python Tkinter Return
<p>Is there a way to return something when a button is pressed?</p>

<p>Here is my sample program.  a simple file reader.  Is the global variable to hold text contents the way to go since I can't return the contents?</p>

<pre><code>from Tkinter import *
import tkFileDialog

textcontents = ''

def onopen():
    filename = tkFileDialog.askopenfilename()
    read(filename)

def onclose():
    root.destroy()

def read(file):
    global textcontents
    f = open(file, 'r')

    textcontents = f.readlines()
    text.insert(END, textcontents)

root = Tk()
root.title('Text Reader')
frame = Frame(root)
frame.pack()
text = Text(frame, width=40, height=20)
text.pack()
text.insert(END, textcontents)

menu = Menu(root)
root.config(menu=menu)

filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Open...", command=onopen)
filemenu.add_command(label="Exit", command=onclose)

mainloop()
</code></pre>
