![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
#Import tkinter library from tkinter import * #Create an instance of tkinter window or frame win=Tk() win.geometry("700x300") def get_input(): value=my_text_box.get("1.0","end-1c") print(value) #Creating a text box widget my_text_box=Text(win, height=5, width=40) my_text_box.pack() #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 comment.pack() win.mainloop()
Output
Running the above code will display a textbox which will accept the input from the user and print the output on the console.
Advertisements