- 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
What is the difference between focus and focus_set methods in Tkinter?
Focus is used to refer to the widget or window which is currently accepting input. Widgets can be used to restrict the use of mouse movement, grab focus, and keystrokes out of the bounds. However, if we want to focus a widget so that it gets activated for input, then we can use focus.set() method. focus() is sometimes referred to as focus_set().
focus_set() focuses on the widget when its window or widget gets focus.
Example
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Define a function to set the focus def set_focus(): entry.focus_set() # Create an Entry widget entry=Entry(win, width=35) entry.pack() # Create a Button to get the focus on any widget ttk.Button(win, text="Set Focus", command=set_focus).pack() win.mainloop()
Output
Executing the above code will display a window that contains a Button and an Entry widget. When we click the button, it will set the focus on the Entry Widget.
- Related Articles
- Difference between title() and wm_title() methods in Tkinter class
- What is the difference between non-static methods and abstract methods in Java?
- What is the difference between functions and methods in JavaScript?
- What is the difference between scipy.cluster.vq.kmeans() and scipy.cluster.vq.kmeans2() methods?
- What is the difference between String.Copy() and String.Clone() methods in C#?
- What is the difference between String.Copy() and String.CopyTo() methods in C#?
- What is the difference between Write() and WriteLine() methods in C#?
- What is the difference between Trim() and TrimStart() methods in C#?
- What is the difference between Read() and ReadLine() methods in C#?
- What is the difference between Math.ceil() and Math.round() methods in JavaScript?
- What is the difference between jQuery.post() and jQuery.get() methods in jQuery?
- What is the difference between jQuery.load() and jQuery.ajax() methods in jQuery?
- What is the difference between jQuery.load() and jQuery.get() methods in jQuery?
- What is the difference between switchClass() and toggleClass() methods in jQuery?
- What is the difference between $.closest() and $.parents() methods in jQuery?

Advertisements