'Text' widgets are used for entering multiple lines of text.
# textbox1.py import tkinter as tk # Py3 root = tk.Tk() textbox = tk.Text(root) textbox.grid() textbox.focus() # save a click root.mainloop() # run the tkinter event loop
Selected keyword arguments in Text()
master=root # the first argument
width=50 # in text units
height=10 # in text units
wrap="none" # line wrapping ("none", "char", "word")
Operations
char = textbox.get("line.char") # rows are numbered from 1
char = textbox.get("1.0") # the first char from the first row
word = textbox.get(first, last)
word = textbox.get("1.0", "1.5") # 5 chars
word = textbox.get("1.0", tk.END) # get all
textbox.delete("line.char")
textbox.delete("1.0")
textbox.delete(first, last)
textbox.delete("1.0", "1.4")
textbox.delete("1.0", tk.END) # remove all
textbox.insert("line.char", "text")
textbox.insert("1.0", "text")
textbox.insert("2.0", "\nThis is a new line.")
textbox.insert(tk.END, "\nPut me at the end!") # insert at the end