Home > Net >  How to place a window in a specific spot while you have resized it to fit a device
How to place a window in a specific spot while you have resized it to fit a device

Time:07-19

I want to be able to resize my windows but have them be placed in a specific spot as well. However I can figure out how to do this. This some example code:

import tkinter

window = tkinter.Tk()
window1 = tkinter.Tk()

width = window.winfo_screenwidth()
height = window.winfo_screenheight()

window.geometry("%dx%d" % (width * 2/3, height)   0   0)
window1.geometry("%dx%d" % (width * 1/3, height)   0   0)

window.mainloop()
window1.mainloop()

If I do this code then I get this error:

TypeError: can only concatenate str (not "int") to str

CodePudding user response:

The official documentation says this about the geometry specification:

NewGeometry has the form =widthxheight±x±y, where any of =, widthxheight, or ±x±y may be omitted.

For example, to place your window so that the upper left corner is at 0,0, you would do something like this:

window.geometry("%dx%d %d %d" % (width * 2/3, height, 0, 0))
  • Related