2

I'm trying to get the physical size of the monitor. I'm able to get the resolution and I want to find the DPI of the screen. Is there any simple way in Python for this?

Machine: Raspberry Pi

Code for finding resolution:

import subprocess

def get_dpi:
   #...code for finding dpi
   return dpi

output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0]
resolution = output.split()[0].split(b'x')
screenWidth =  int(resolution[0].decode('utf-8'))
screenHeight =  int(resolution[1].decode('utf-8'))

screenDpi = get_dpi()

#print(screenWidth,screenDpi)
# get actual screen width and height in inches
physicalWidth = screenWidth/screenDpi 
physicalHeight = physicalHeight/screenDpi 
print(physicalWidth, physicalHeight)
Shyam3089
  • 459
  • 1
  • 5
  • 20
  • Does this answer your question? [Calculate screen DPI](https://stackoverflow.com/questions/54271887/calculate-screen-dpi) – CDJB Jan 08 '20 at 12:37
  • Or, for screen size directly without worrying about dpi, [this might help](https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python/31171430#31171430) – CDJB Jan 08 '20 at 12:38
  • @CDJB This only returns pixel size. – Shyam3089 Jan 08 '20 at 13:29

0 Answers0