Есть ли способ вернуть что-либо, когда нажата кнопка?
Вот мой пример программы.простая программа для чтения файловЯвляется ли глобальная переменная для хранения текстового содержимого способом, поскольку я не могу вернуть содержимое?
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()