# a look at the Tkinter Text widget
# use ctrl+c to copy, ctrl+x to cut selected text,
# ctrl+v to paste, and ctrl+/ to select all
import Tkinter as tk
def get_text():
# get text widget contents between start_index and end_index
# start_index = "%d.%d" % (line, column) here "1.0"
# line starts with 1 and column with 0
# here end_index = tk.END
# set the label text to the typed-in text
v1.set(text1.get(1.0, tk.END))
# clear the text
text1.delete(1.0, tk.END)
text1.insert(tk.INSERT, ' new text')
text1.insert(tk.INSERT, '\n and more text')
# this sets the window title caption too
# without the leading space Text will be text!?
root = tk.Tk(className = " Text, Button, Label ...")
# text entry field, width=width chars, height=lines text
text1 = tk.Text(root, width=50, height=2, bg='yellow')
text1.pack()
# function listed in command will be executed on button click
button1 = tk.Button(root, text='get the text', command=get_text)
button1.pack(pady=5)
# define a variable to hold the label text
v1 = tk.StringVar()
# label text will always be the textvariable's value
# width/height in char size
label1 = tk.Label(root, textvariable=v1, width=50, height=2)
label1.pack(pady=5)
# do some caculation and format result
pi_approx = 355/113.0
str1 = "%.4f" % (pi_approx) # 3.1416
# show result in text widget
text1.insert(tk.INSERT, str1)
# start cursor in text1
text1.focus()
root.mainloop()