
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Connect a Variable to the Tkinter Entry Widget
Tkinter Entry widget is an Input widget that supports and accepts single-line user input. It accepts all types of characters in UTF-8 module. In order to get the input from the Entry widget, we have to define a variable (based on Data Types it accepts) that accepts only string characters. Then, by using get() method, we can print the given input from the Entry widget.
Example
# Import the Tkinter Library from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry of window win.geometry("700x250") # Define a String Variable var = StringVar() # Define a function to print the Entry widget Input def printinput(*args): print(var.get()) # Create an Entry widget entry = Entry(win, width=35, textvariable=var) entry.pack() # Trace the Input from Entry widget var.trace("w", printinput) win.mainloop()
Output
Running the above code will display a window with an Entry widget.
When we write something in the Entry widget, it will just print out all the characters from the Entry widget on the console.
H He Hel Hell Hello Hello Hello W Hello Wo Hello Wor Hello Worl Hello World Hello World!
Advertisements