- Trending Categories
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 do I bind the enter key to a function in Tkinter?
Pressing a key and handling some operation with the key is an event that can be triggered through a button. We can bind the key event using the Binding method in a tkinter application.
Whenever the key will be triggered, it will call a handler that will raise the specific operation for the key event.
If we want to trigger the Enter key with the bind function, we will use the bind('<Key>', Handler) method. For Enter Key, we use bind('<Return>', Handler) function.
Example
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") def handler(e): label= Label(win, text= "You Pressed Enter") label.pack() #Create a Label Label(win, text= "Press Enter on the Keyboard", font= ('Helvetica bold', 14)).pack(pady=20) #Bind the Enter Key to Call an event win.bind('<Return>',handler) win.mainloop()
Output
It will display the following window −
Now, if we will press "Enter" on the keyboard, it will display “You Pressed Enter”.
- Related Articles
- How to bind the Enter key to a tkinter window?
- How to bind a key to a button in Tkinter?
- How to bind the spacebar key to a certain method in Tkinter?
- How to bind the Escape key to close a window in Tkinter?
- How to bind multiple events with one "bind" in Tkinter?
- How to bind to shift+tab in Tkinter?
- How to bind all the number keys in Tkinter?
- How to bind a click event to a Canvas in Tkinter?
- How to bind events to Tkinter Canvas items?
- Call the same function when clicking a Button and pressing Enter in Tkinter
- How to apply bind() function in JavaScript?
- How do I close a tkinter window?
- How do I create a popup window in Tkinter?
- How do I create a date picker in tkinter?
- How do I display tooltips in Tkinter?

Advertisements