Application window geometry specifier

Igor Korot ikorot01 at gmail.com
Tue Jan 12 11:57:44 EST 2021


Hi,

On Tue, Jan 12, 2021 at 10:47 AM Chris Angelico <rosuav at gmail.com> wrote:
>
> 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.

Keep in mind that if you target Linux, the "modern" window server (Wayland)
will not allow user code to decide the positioning and size of the TLW.

Instead some renderer will make the decision for you and place it appropriately.

So you may re-think that design. ;-)

Thank you.


>> 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
> --
> https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list