473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2584
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5531
by: MSE | last post by:
How can I make a website that adapts to the screen resolution? I would also like to include a picture that stretches when the screen res. increases, if you know what I mean.
5
4388
by: Chris | last post by:
After exhausting my search on the MS website, I can't find a straight answer. I fin dit hard to believe that MS left our something so useful in ASP.NET as screen resolution detection. Problem:...
9
3383
by: Les Juby | last post by:
I understand that there are several ways to effectively control the browser delivery of HTML to make the most effective use of the different screen resolutions today. (And in the foreseeable...
5
3773
by: jlombardo | last post by:
I've read previous posts and know it is "bad form" to change a user's screen resolution to fit your program's needs. My situation is very different. I have a user with a laptop resolution of...
5
2898
by: VJ | last post by:
Is there a any known easy way to fit web pages for a screen resolution. Can I do this programmatically? VJ
7
9917
by: Robert Bull | last post by:
I have created an asp.net app on my machine where the resolution is set to 1280 x 1024. When my users view the form on their screen, some of the controls display differently than on my screen. One...
4
1962
by: Agnes | last post by:
MY application is designed based on 800 X600 screen size. However, some client use 1024 X768 , When they run the application, the form become smaller. I don't want to re-wrtie all the forms How...
1
3486
by: Mufasa | last post by:
I have some machines that apparently are having the screen resolution changed based on group policies ( this is what my Network Engineer is telling me ). These machines are at customer sites so we...
6
3010
mikek12004
by: mikek12004 | last post by:
I want to load a different swf in PHP based on the viewer's screen resolution. All would be fine if I could get the screen resolution in a variable in PHP. Problem is that after I done a bit of a...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.