Application window geometry specifier
Chris Angelico
rosuav at gmail.com
Tue Jan 12 11:44:38 EST 2021
On Wed, Jan 13, 2021 at 3:38 AM Rich Shepard <rshepard at appl-ecosys.com> wrote:
>
> 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.
>
Do the offsets need to be integers?
ChrisA
More information about the Python-list
mailing list