[Tutor] Getting the screen size....using Tkinter
Michael Lange
klappnase at freenet.de
Mon Dec 4 23:49:47 CET 2006
On Mon, 4 Dec 2006 16:43:42 +0000
"Asrarahmed Kadri" <ajkadri at googlemail.com> wrote:
> Hi folks,
>
> Is it possible to get the screen size using a standard API of Tkinter?
>
> And also any function to position the window in the center of the screen..??
>
> Thanks in anticipation.
>
You might want to have a look at Pmw's _centreonscreen method:
def _centreonscreen(self):
# Centre the window on the screen. (Actually halfway across
# and one third down.)
parent = self.winfo_parent()
if type(parent) == types.StringType:
parent = self._hull._nametowidget(parent)
# Find size of window.
self.update_idletasks()
width = self.winfo_width()
height = self.winfo_height()
if width == 1 and height == 1:
# If the window has not yet been displayed, its size is
# reported as 1x1, so use requested size.
width = self.winfo_reqwidth()
height = self.winfo_reqheight()
# Place in centre of screen:
x = (self.winfo_screenwidth() - width) / 2 - parent.winfo_vrootx()
y = (self.winfo_screenheight() - height) / 3 - parent.winfo_vrooty()
if x < 0:
x = 0
if y < 0:
y = 0
return '+%d+%d' % (x, y)
If you replace self resp. self._hull with your window and pass the return value to
a call of its geometry() method it should do what you want.
I hope this helps
Michael
More information about the Tutor
mailing list