469,579 Members | 1,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Screen placement based on screen resolution

Pat
I am trying to place a dialog in the center of the screen based on a users
screen resolution.
I can get the width and height of the screen, but I can't seem to use the
following:

root.geometry('WxH+X+Y')

It appears the values for X and Y need to be integers and not a variable
like width/2-40
S
Apr 7 '06 #1
5 2450
Tkinter takes strings as its arguments; it's TCL's legacy. You can use
string formatting for this:

x = width/2-40
y = height/2-30

root.geometry('%ldx%ld+%ld+%ld' % (width, height, x, y))

Apr 7 '06 #2
Pat
Thanks.
S
"Lonnie Princehouse" <fi**************@gmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
Tkinter takes strings as its arguments; it's TCL's legacy. You can use
string formatting for this:

x = width/2-40
y = height/2-30

root.geometry('%ldx%ld+%ld+%ld' % (width, height, x, y))

Apr 7 '06 #3
"Pat" <pa******@adelphia.net> wrote:
I am trying to place a dialog in the center of the screen based on a users
screen resolution. I can get the width and height of the screen, but I can't
seem to use the following:

root.geometry('WxH+X+Y')

It appears the values for X and Y need to be integers and not a variable
like width/2-40


Python doesn't look in string literals for things that might look
like expressions, but if you have the values, *creating* a string
with the right contents is pretty easy. see the tutorial for the
basics:

http://docs.python.org/tut/node9.html

if you have all the values in variables, this expression sets the
geometry in one step:

root.geometry("%dx%d%+d%+d" % (width, height, xoffset, yoffset))

also see

http://effbot.org/tkinterbook/wm.htm...eometry-method

which includes code that parses a geometry string.

</F>

Apr 8 '06 #4
Lonnie Princehouse wrote:
Tkinter takes strings as its arguments; it's TCL's legacy.
geometry strings are an X windows thing...
You can use string formatting for this:

x = width/2-40
y = height/2-30

root.geometry('%ldx%ld+%ld+%ld' % (width, height, x, y))


note that "+%ld" (why bother with the l, btw? Python's not C) will
misbehave if you pass in a negative offset. better use "%+d".

</F>

Apr 8 '06 #5
Pat
Thanks a lot for you response.
S
"Fredrik Lundh" <fr*****@pythonware.com> wrote in message
news:ma***************************************@pyt hon.org...
"Pat" <pa******@adelphia.net> wrote:
I am trying to place a dialog in the center of the screen based on a
users
screen resolution. I can get the width and height of the screen, but I
can't
seem to use the following:

root.geometry('WxH+X+Y')

It appears the values for X and Y need to be integers and not a variable
like width/2-40


Python doesn't look in string literals for things that might look
like expressions, but if you have the values, *creating* a string
with the right contents is pretty easy. see the tutorial for the
basics:

http://docs.python.org/tut/node9.html

if you have all the values in variables, this expression sets the
geometry in one step:

root.geometry("%dx%d%+d%+d" % (width, height, xoffset, yoffset))

also see

http://effbot.org/tkinterbook/wm.htm...eometry-method

which includes code that parses a geometry string.

</F>

Apr 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by MSE | last post: by
5 posts views Thread by Chris | last post: by
9 posts views Thread by Les Juby | last post: by
5 posts views Thread by jlombardo | last post: by
5 posts views Thread by VJ | last post: by
7 posts views Thread by Robert Bull | last post: by
4 posts views Thread by Agnes | last post: by
1 post views Thread by Mufasa | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.