As David Heffernan mentioned, you can use GetMonitorInfo
with pywin32
to retrieve the monitor size. In particular, the work area will exclude the size of the taskbar.
To get the work area size (desktop minus taskbar):
from win32api import GetMonitorInfo, MonitorFromPoint
monitor_info = GetMonitorInfo(MonitorFromPoint((0,0)))
work_area = monitor_info.get("Work")
print("The work area size is {}x{}.".format(work_area[2], work_area[3]))
The work area size is 1366x728.
To get the taskbar height:
from win32api import GetMonitorInfo, MonitorFromPoint
monitor_info = GetMonitorInfo(MonitorFromPoint((0,0)))
monitor_area = monitor_info.get("Monitor")
work_area = monitor_info.get("Work")
print("The taskbar height is {}.".format(monitor_area[3]-work_area[3]))
The taskbar height is 40.
Explanation
First, we need to create a handle referencing the primary monitor. The primary monitor always has its upper left corner at 0,0, so we can use:
primary_monitor = MonitorFromPoint((0,0))
We retrieve information about the monitor with GetMonitorInfo()
.
monitor_info = GetMonitorInfo(primary_monitor)
# {'Monitor': (0, 0, 1366, 768), 'Work': (0, 0, 1366, 728), 'Flags': 1, 'Device': '\\\\.\\DISPLAY1'}
The monitor information is returned as a dict
. The first two entries represent the monitor size and the work area size as tuples (x position, y position, height, width).
work_area = monitor_info.get("Work")
# (0, 0, 1366, 728)