How to Get the Input From the Tkinter Text Widget
In this tutorial, we are going to see how to get the input from the Tkinter Text Widget in Python. The Text widget has a get() method to get the user entered Text value, which has a starting position argument, and an optional ending argument to specify the ending position of the text to retrieve.
get(start, end=None)
If ‘end’ is not specified, a single character specified at the start position will be returned.
How to Get the Input From the Tkinter Text Widget
import tkinter as tk gui = tk.Tk() gui.geometry("300x150") def getText(): res = texte.get("1.0","end") print(res) texte = tk.Text(gui, height=5) texte.pack() btn = tk.Button(gui, height=1, width=10, text="Read", command=getText) btn.pack(pady=20) gui.mainloop()
Output:
