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_set() methods are also universal widget methods. They can also be applied on
This method is used to set the focus on the desired widget if and only if the master window is focused.
Below is the Python program-
You may observe in above image that Button widget has the focus. For better understanding copy and run above program.
This method returns the name of the widget which currently has the focus.
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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Difference between Method Overloading and Method Overriding in Python
- Python | Using variable outside and inside the class and method
- class method vs static method in Python
- Difference between Method and Function in Python
- Python PIL | logical_and() and logical_or() method
- Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method
- Python | forget_pack() and forget_grid() method in Tkinter
- Python math library | isfinite() and remainder() method
- Python PIL | ImageEnhance.Color() and ImageEnhance.Contrast() method
- Python PIL | ImageChops.screen() and ImageChops.offset() method
- Python PIL | MedianFilter() and ModeFilter() method
- Python PIL | getbands() and getextrema() method
- Python PIL | paste() and rotate() method
- Python | os.geteuid() and seteuid() method
- Python | os.getgid() and os.setgid() method
- Python | os.getuid() and os.setuid() method
- Python PIL | MinFilter() and MaxFilter() method
- Python | os.getresuid() and os.setresuid() method
- Python | os.getegid() and os.setegid() method
- Python | os.getresgid() and os.setresgid() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.