How to get the input from the Tkinter Text Widget?

In tkinter, we can create text widgets using Text attributes using packages. However, while creating a GUI application, sometimes we need to capture the input from a text widget.

We can get the input from the user in a text widget using the .get() method. We need to specify the input range which will be initially from 1.0 to END that shows the characters starting and ending till the END.


#Import tkinter library
from tkinter import *

#Create an instance of tkinter window or frame

def get_input():

#Creating a text box widget
my_text_box=Text(win, height=5, width=40)

#Create a button for Comment
comment= Button(win, height=5, width=10, text="Comment", command=lambda: get_input())

#command=get_input() will wait for the key to press and displays the entered text



Running the above code will display a textbox which will accept the input from the user and print the output on the console.

Updated on: 13-Jul-2021

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started