Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set focus on Tkinter window (depends on platform?)

I have a Tkinter program and running it like: python myWindow.py starts it all right, but the window is behind the terminal that I use to start it.

Is there a way to make it grab the focus and be the foreground application? Does it depend on the platform?

like image 494
Bogdan Balan Avatar asked May 23 '11 00:05

Bogdan Balan


People also ask

How to set focus in tkinter?

By using the focus_set() method, we can activate the focus on any widget and give them priority while executing the application.

What is the use of focus() in 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.

Which function's is are used to set the tkinter window size?

In Tkinter, minsize() method is used to set the minimum size of the Tkinter window. Using this method user can set window's initialized size to its minimum size, and still be able to maximize and scale the window larger. Here, height and width are in pixels.

How do you set the window to the middle of the screen in tkinter?

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center. We can also set the window to its center programmatically by defining its geometry.


1 Answers

This might be a feature of your particular window manager. One thing to try is for your app to call focus_force at startup, after all the widgets have been created.

like image 59
Bryan Oakley Avatar answered Sep 28 '22 22:09

Bryan Oakley