Application window geometry specifier
Rich Shepard
rshepard at appl-ecosys.com
Tue Jan 12 11:37:15 EST 2021
I want my application's window (main frame) to open centered on the
monitor's screen. This code:
# open application centered on screen; set window width and height
self.appwidth = 600
self.appheight = 500
# get screen width and height
self.scrwidth = self.winfo_screenwidth()
self.scrheight = self.winfo_screenheight()
# formula to find screen center
self.xLeft = (self.scrwidth/2) - (self.appwidth/2)
self.yTop = (self.scrheight/2) - (self.appheight/2)
# set geometry
self.geometry(str(self.appwidth) + "x" + str(self.appheight) +
"+" + str(self.xLeft) + "+" + str(self.yTop))
generates this error when run:
File "/usr/lib64/python3.9/tkinter/__init__.py", line 2036, in wm_geometry
return self.tk.call('wm', 'geometry', self._w, newGeometry)
_tkinter.TclError: bad geometry specifier "600x500+340.0+262.0"
As the geometry string represents window width times window height plus x-offset
plus y-offset I'm not seeing my error.
Please show me what's wrong with specifier.
TIA,
Rich
More information about the Python-list
mailing list