【转载】 Python 调整屏幕分辨率

转载来自: http://www.cnblogs.com/fatterbetter/p/4115423.html

 

需要用windows的api,ChangeDisplaySettings 

实现代码如下:

1 import win32api
2 dm = win32api.EnumDisplaySettings(None, 0)
3 dm.PelsHeight = 900
4 dm.PelsWidth = 1400
5 dm.BitsPerPel = 32
6 dm.DisplayFixedOutput = 0
7 win32api.ChangeDisplaySettings(dm, 0)

其中,一开始没有设置DisplayFixedOutput的值,在我机器上的效果是,切到小分辨率时,屏幕只在中间一小块,而在系统中调整时,是可以拉伸的,后来才找到是这个值在起作用

MSDN上的解释为

ValueMeaning 
DMDFO_DEFAULTThe display's default setting.#define DMDFO_DEFAULT   0
DMDFO_CENTERThe low-resolution image is centered in the larger screen space.#define DMDFO_CENTER    2
DMDFO_STRETCHThe low-resolution image is stretched to fill the larger screen space. #define DMDFO_STRETCH   1

将值设为1,或者0,在我机器上都为拉伸

有了这个脚本,需要改变分辨率时,只需双击一下

 

 

 

Linux 命令行修改分辨率

通过 xrandr 命令查看本机屏显配置

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
VGA-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080     60.00*+
   1680x1050     59.95  
   1280x1024     75.02    60.02  
   1440x900      59.89  
   1280x960      60.00  
   1280x720      60.00  
   1024x768      75.03    70.07    60.00  
   832x624       74.55  
   800x600       72.19    75.00    60.32    56.25  
   640x480       75.00    72.81    66.67    59.94  
   720x400       70.08  
HDMI-1 disconnected (normal left inverted right x axis y axis)
DVI-D-1 disconnected (normal left inverted right x axis y axis)

修改分辨率:

xrandr --output VGA-1 --mode 1024x768

参考: https://wiki.ubuntu.com/X/Config/Resolution

 

转载于:https://www.cnblogs.com/dcb3688/p/4408764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值