
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
Give Focus to a Python Tkinter Text Widget
In various applications, tkinter widgets are required to be focused to make them active. Widgets can also grab focus and prevent the other events outside the bounds. To manage and give focus to a particular widget, we generally use the focus_set() method. It focuses the widget and makes them active until the termination of the program.
Example
In the following example, we have created two widgets: an Entry widget and a text widget in the same window. By using the focus_set() method, we will activate the focus on the text widget.
#Import tkinter library from tkinter import * from PIL import Image,ImageTk #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("750x250") #Create a Text WIdget text= Text(win, width= 30, height= 10) text.insert(INSERT, "Hello World!") #Activate the focus text.focus_set() text.pack() #Create an Entry Widget entry=Entry(win,width= 30) entry.pack() win.mainloop()
Output
Running the above code will display a window that contains the focus on the text widget.
Advertisements