



Tkinter winfo exists windows#
For example, xfwm4 has smart placement, which places windows side by side until the screen is full.
Tkinter winfo exists code#
You might want to consider providing the user with an option to center the window, and not center by default otherwise, your code can interfere with the window manager's functions. I use deiconify() as a trick to activate the window. Using withdraw() or iconify() later followed by deiconify() doesn't seem to work well, for this purpose, on Windows 7. attributes('-alpha', 0.0) to make the window fully transparent and then set it to 1.0 after the window has been centered. One way to prevent seeing the window move across the screen is to use The simplest (but possibly inaccurate) method is to use tk::PlaceWindow, which takes the pathname of a toplevel window as an argument. If you don't want to use both, PyQt and Tkinter, maybe it would be better to go with PyQt from start. So, it does the work by putting the window on center of that screen. PyQt from the other hand, doesn't see multi-monitors environment either, but it will get only the resolution of the Top-Left monitor (Imagine 4 monitors, 2 up and 2 down making a square). So, you 'll get the total resolution of all screens together and your window will end-up somewhere in the middle of the screens. Tkinter doesn't see if there are 2 or more monitors extended horizontal or vertical. I am calling update_idletasks method before retrieving the width and the height of the window in order to ensure that the values returned are accurate. Size = tuple(int(_) for _ in toplevel.geometry().split('+').split('x')) Screen_height = app.desktop().screenGeometry().height() Screen_width = app.desktop().screenGeometry().width() # screen_height = toplevel.winfo_screenheight() # screen_width = toplevel.winfo_screenwidth() # Tkinter way to find the screen resolution Combining GUI toolkits results in an unreasonably large dependency.You can try to use the methods winfo_screenwidth and winfo_screenheight, which return respectively the width and height (in pixels) of your Tk instance (window), and with some basic math you can center your window: import tkinter as tk If the multi-monitor scenario concerns you, then you can either look into the screeninfo project, or look into what you can accomplish with Qt (PySide2) or GTK (PyGObject), and then use one of those toolkits instead of tkinter. It can also be set to center all windows, in which case you won't have the problem of seeing the window move (as addressed above).
