VOOZH about

URL: https://www.geeksforgeeks.org/python/python-focus_set-and-focus_get-method/

⇱ Python | focus_set() and focus_get() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | focus_set() and focus_get() method

Last Updated : 25 Jun, 2019
Tkinter has a number of widgets to provide functionality in any GUI. It also supports a variety of universal widget methods which can be applied on any of the widget. focus_get() and focus_set() methods are also universal widget methods. They can also be applied on Tk() method.

focus_set() method-

This method is used to set the focus on the desired widget if and only if the master window is focused. Syntax:
widget.focus_set()
Below is the Python program- Output: 👁 Image
You may observe in above image that has the focus. For better understanding copy and run above program.

focus_get() method-

This method returns the name of the widget which currently has the focus. Syntax:
master.focus_get()
Note: You can use it with any of the widget, master in not necessary. Below is the Python program -
Output: Every time you click on any widget OR if you click the mouse button-1 above program will print the name of the widget which has the focus. For better understanding copy and run above program.
.!radiobutton has focus
.!entry has focus
.!button has focus
Comment
Article Tags: