Query screen resolution?

A

AK Eric

Thought this would be easy, maybe I'm missing something :) Trying to
query the x,y resolution of my screen. I've seen this available
through http://python.net/crew/mhammond/win32/ :

from win32api import GetSystemMetrics
print "width =", GetSystemMetrics (0)
print "height =",GetSystemMetrics (1)

But I was hoping for something built-in, and something non-OS
specific. Is that available? Would be nice to detect for multiple
monitors as well, but I'm probably asking too much :)

Thanks!
 
W

Warpcat

I don't know about built-ins, but I do believe that pygame (which *is*  
cross-platform) will let you get at that information:
       http://www.pygame.org/docs/ref/display.html#pygame.display..Info

Actually, I just came up with another hack using PyGame as well like
so:

screen = pygame.display.set_mode((0,0))
WIDTH, HEIGHT = screen.get_size()

If you pass zero values into the resolution, it will pop to the
current screen resolution. And since I'm making a PyGame app, this
actually works out ok. However, querying the current_w & current_h
attrs from the Info object is a lot cleaner (I was unaware of that,
thanks!)

But I'd sure like to know if there is built-in way.
 
N

Nobody

Thought this would be easy, maybe I'm missing something :) Trying to
query the x,y resolution of my screen. I've seen this available
through http://python.net/crew/mhammond/win32/ :

from win32api import GetSystemMetrics
print "width =", GetSystemMetrics (0)
print "height =",GetSystemMetrics (1)

But I was hoping for something built-in, and something non-OS
specific. Is that available? Would be nice to detect for multiple
monitors as well, but I'm probably asking too much :)

Your question is based upon the notion that "the screen" is a meaningful
concept. Once you move away from Windows (and systems which intentionally
try to be like Windows), that's no longer true.

E.g. if the program is being run on a terminal, the screen size is
measured in characters, not pixels (80x25 would be a reasonable size). If
the program is being run as a cron job or CGI script, there is no screen.

OTOH, if the system has the X libraries installed, there are a practically
unlimited number of X displays which you could connect to, provided that
you have the appropriate authentication credentials.
 
W

Warpcat

Your question is based upon the notion that "the screen" is a meaningful
concept. Once you move away from Windows (and systems which intentionally
try to be like Windows), that's no longer true.

Good points. Always something I haven't thought of. Ok so... let's
*presume* the user has a measurable screen on win\mac\linux\etc since
on any other OS they wouldn't be running the app....
 
N

Nobody

Good points. Always something I haven't thought of. Ok so... let's
*presume* the user has a measurable screen on win\mac\linux\etc since
on any other OS they wouldn't be running the app....

If it's a GUI app, you ask the GUI toolkit which you're using.

[And if it isn't a GUI app, why would the screen resolution be relevant?]
 
W

Warpcat

If it's a GUI app, you ask the GUI toolkit which you're using.

Heh, I suppose you're right :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top