Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting focus to specific TKinter entry widget

Tags:

I'd like to set the focus of my program to a specific entry widget so that I can start entering data straight-away - how can I do this?

My current code

from Tkinter import * root = Tk() frame=Frame(root,width=100,heigh=100,bd=11) frame.pack() label = Label(frame,text="Enter a digit that you guessed:").pack() entry= Entry(frame,bd=4) entry.pack()  button1=Button(root,width=4,height=1,text='ok') button1.pack()  root.mainloop() 
like image 329
Leo Avatar asked Nov 29 '12 13:11

Leo


People also ask

How do you set focus to entry in Python?

Build A Paint Program With TKinter and Python Let us suppose that there are some widgets present in an application such that we have to focus on a particular widget. By using the focus_set() method, we can activate the focus on any widget and give them priority while executing the application.

What does focus () do Tkinter?

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.

How do you take input from an entry widget?

An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.

Which widget we use for entry data in Tkinter?

The Entry widget is used to accept single-line text strings from a user. If you want to display multiple lines of text that can be edited, then you should use the Text widget. If you want to display one or more lines of text that cannot be modified by the user, then you should use the Label widget.


Video Answer


1 Answers

Use entry.focus():

from Tkinter import * root = Tk() frame=Frame(root,width=100,heigh=100,bd=11) frame.pack() label = Label(frame,text="Enter a digit that you guessed:").pack() entry= Entry(frame,bd=4) entry.pack() entry.focus() button1=Button(root,width=4,height=1,text='ok') button1.pack()  root.mainloop() 
like image 124
unutbu Avatar answered Oct 25 '22 22:10

unutbu