- 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 do I print and have user input in a text box 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 containing a text widget. Type something in the text widget and click the "Print" button to display the output.
- Related Articles
- How do I center the text in a Tkinter Text widget?
- How to take input in a text widget and display the text in tkinter?
- Taking input from the user in Tkinter
- Python Tkinter – How do I change the text size in a label widget?
- How do I give focus to a python Tkinter text widget?
- How to have image and text in one button in Tkinter?
- How to display LaTex in real time in a text box in Tkinter?
- How can I create a simple message box in Tkinter?
- How to insert text at the beginning of the text box in Tkinter?
- How to set justification on Tkinter Text box?
- Specify the dimensions of a Tkinter text box in pixels
- How to input text in the text box without calling the sendKeys() using Selenium?
- How to Delete Tkinter Text Box's Contents?
- How do I display tooltips in Tkinter?
- How do I create a popup window in Tkinter?

Advertisements