- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
#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()
Running the above code will display a textbox which will accept the input from the user and print the output on the console.
- How to erase everything from the Tkinter text widget?
- How to take input in a text widget and display the text in tkinter?
- How to get the current length of the Text in a Tkinter Text widget?
- Get the text of a button widget in Tkinter
- How to erase everything from a Tkinter text widget?
- How to make the Tkinter text widget read only?
- Change the focus from one Text widget to another in Tkinter
- How to get the width of the Tkinter widget?
- How to highlight text in a tkinter Text widget?
- How to clear the contents of a Tkinter Text widget?
- How do I center the text in a Tkinter Text widget?
- How to get the input from a Checkbox in Python Tkinter?
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- Return the input of the Entry widget in Tkinter
- How to get the widget name in the event in Tkinter?