Search code examples
pythonuser-interfacetkintergeometrywindow

Understanding of Tkinter Window geometry


to create a fullscreen window in Python through Tkinter i do this:

w, h = window.winfo_screenwidth(), window.winfo_screenheight()
window.geometry("%dx%d+0+0" % (w, h))

And it works, of course. But I'd like to know why it is like this. Why am I typing "%dx%d+0+0"? What does Python read in that command?


Solution

  • w, h = window.winfo_screenwidth(), window.winfo_screenheight()

    w, and h are now holding the value of the screen height and width, say 1280, and 920

    window.geometry("%dx%d+0+0" % (w, h))

    Then it is a straightforward python string formatting (the old fashion way):

    window.geometry("1280x920+0+0")

    which is a string that tkinter can parse. (welcome to the 1990'es)