(win10专业版 python 3.8.9 32位测试可用)
不想pip安装第三方库,使用python内置库获取本机屏幕分辨率。我总结了两种方式:
import ctypes
from tkinter import *
def get_screen_size_by_ctypes(): # python内置库获取屏幕分辨率方式一
return (ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1))
def get_screen_size_by_tkinter(): # python内置库获取屏幕分辨率方式二
root = Tk()
return (root.winfo_screenwidth(), root.winfo_screenheight())
print(get_screen_size_by_ctypes())
print(get_screen_size_by_tkinter())