-1

There are a number of topics (Get window position & size with python) that address how to get the position and size of a window on an individual OS basis.

Is there a way to do this that's system-agnostic?

Stevphen
  • 205
  • 1
  • 8

1 Answers1

1

I am not sure about a system-agnostic way of handling it, but when ever I run into an issue related to system specific operations. I will insert a platform check.

from sys import platform
if platform == "linux":
    # linux
elif platform == "darwin":
    # OS X
elif platform == "windows":
    # Windows...

From there I can write out the appropriate operations for what ever task I need to complete on each platform.

Michael
  • 174
  • 2
  • 13
  • That's a great idea, if no one comes in with an explicit answer I'll accept this one in a few days. I'm not amazingly keen on re-writing things on a per OS basis (OS X and Windows in my case) but if it works it works! – Stevphen Feb 11 '22 at 15:25
  • @Stevphen There are a number of operations that are OS-specific, and the only way around it is to check the platform that you're on and set flags for the operations. So, while there may be a single way to do what you're looking at across all platforms, it's not uncommon that some operations will need to be handled this way. Best of luck. – Michael Feb 11 '22 at 15:37
  • That makes sense, however I'm able to (without refactor) run a lot of my python code across both OSx and Windows so I was hoping (despite no luck googling!) there would be a way to at least evaluate window size and position. It's for GUI interactions on the same application across both operating systems, so I figured I can define a function to establish the % of the window (x, y) to interaction with. – Stevphen Feb 11 '22 at 15:47