import tkinter as tk
parent = tk.Tk()
# create the widget. Make sure to save a reference.
mytext = tk.Text(parent)
# insert a string at the beginning
mytext.insert('1.0', "I love my text widget!")
# insert a string into the current text
mytext.insert('1.2', 'REALLY ')
# get the whole string
mytext.get('1.0', tk.END)
# delete the last character.
# Note that there is always a newline character
# at the end of the input, so we backup 2 chars.
mytext.delete('end - 2 chars')
mytext.pack()
parent.mainloop()
Recent Comments