How to do it...
Python is truly great. All we have to do to set the focus to a specific control when the GUI appears is call the focus() method on an instance of a tkinter widget we previously created. In our current GUI example, we assigned the ttk.Entry class instance to a variable named, name_entered. Now, we can give it the focus.
Place the following code just above the code which is located at the bottom of the module and which starts the main windows event loop, like we did in the previous recipes:
If you get some errors, make sure you are placing calls to variables below the code where they are declared. We are not using OOP as of yet, so this is still necessary. Later, it will no longer be necessary to do this.
Adding this one line (38) of Python code places the cursor in our text Entry widget, giving the text Entry widget the focus. As soon as the GUI appears, we can type into this text box without having to click it first.
We can also disable widgets. To do that, we will set a property on the widget. We can make the button disabled by adding this one line (37 below) of Python code to create the button:
After adding the preceding line of Python code, clicking the button no longer creates any action: