- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 take input in a text widget and display the text in tkinter?
We can use the Tkinter text widget to insert text, display information, and get the output from the text widget. To get the user input in a text widget, we've to use the get() method. Let's take an example to see how it works.
Example
# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") def get_input(): label.config(text=""+text.get(1.0, "end-1c")) # Add a text widget text=Text(win, width=80, height=15) text.insert(END, "") text.pack() # Create a button to get the text input b=ttk.Button(win, text="Print", command=get_input) b.pack() # Create a Label widget label=Label(win, text="", font=('Calibri 15')) label.pack() win.mainloop()
Output
Running the above code will display a window with a text widget and a button to print and display the output. When you type something in the text widget and click on the "Print" button, it will display the output at the bottom in a label widget.
- Related Articles
- How to highlight text in a tkinter Text widget?
- How to get the input from the Tkinter Text Widget?
- Python Tkinter – How to display a table editor in a text widget?
- How do I center the text in a Tkinter Text widget?
- How to get the current length of the Text in a Tkinter Text widget?
- How to create hyperlink in a Tkinter Text widget?
- How to attach a vertical scrollbar in Tkinter text widget?
- Underline Text in Tkinter Label widget
- How to attach a Scrollbar to a Text widget in Tkinter?
- Undo and redo features in a Tkinter Text widget
- How to insert a temporary text in a tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to erase everything from a Tkinter text widget?
- Get the text of a button widget in Tkinter
- How to make the Tkinter text widget read only?

Advertisements