def get_pyqt_screen_size(): app = QApplication([]) screen = app.primaryScreen() size = screen.size() width, height = size.width(), size.height() return width, height screen_width, screen_height = get_pyqt_screen_size() print(f"PyQt Screen width: {screen_width}, Screen height: {s...
app=Flask(__name__)# 数据库连接和查询defget_screen_width():conn=sqlite3.connect('screen_width.db')c=conn.cursor()c.execute("SELECT width FROM screen_width ORDER BY id DESC LIMIT 1")result=c.fetchone()conn.close()returnresult[0]ifresultelseNone# Web界面路由@app.route('/')defhome()...
import pyautogui width, _ = pyautogui.size() print(f"屏幕宽度: {width} 像素") 方法三:使用 screeninfo 模块 screeninfo 是一个专门用于获取屏幕信息的库。 python from screeninfo import get_monitors monitor = get_monitors()[0] screen_width = monitor.width print(f"屏幕宽度: {screen_width} ...
安装完成后,我们可以使用screeninfo库来获取屏幕的宽度和高度。 fromscreeninfoimportget_monitors# 获取屏幕信息monitors=get_monitors()# 获取第一个屏幕的宽度和高度screen_width=monitors[0].width screen_height=monitors[0].height# 打印屏幕宽度和高度print("屏幕宽度:",screen_width)print("屏幕高度:",screen_he...
screen_height=win32api.GetSystemMetrics(win32con.SM_CYFULLSCREEN)print("屏幕宽度:", screen_width)print("屏幕高度:", screen_height)#for num in range(84):#print( "num=",num,"size=",win32api.GetSystemMetrics(num))hwnd =win32gui.GetDesktopWindow() ...
screen_size=get_screen_size() proportion= round(real_resolution['width'] / screen_size['width'], 2)returnproportionprint("屏幕真实分辨率:",get_real_screen_resolution()["width"],'x', get_real_screen_resolution()["height"])print("缩放后的屏幕分辨率:",get_screen_size()["width"],'x',...
proportion =round(real_resolution['width'] / screen_size['width'],2)returnproportionprint("屏幕真实分辨率:",get_real_screen_resolution()["width"],'x', get_real_screen_resolution()["height"])print("缩放后的屏幕分辨率:",get_screen_size()["width"],'x', get_screen_size()["height"])pr...
canvas.create_image(screenWidth//2, screenHeight//2, anchor = tkinter.CENTER, image=self.image) # 获取鼠标左键抬起的位置,取色 def onLeftButtonUp(event): im = Image.open(png) # retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates color = im.get...
importpygame# 初始化Pygamepygame.init()# 设置窗口大小screen_width=800screen_height=600# 创建窗口...
screen_width,_=gw.getWindows()[0].sizeprint(f"屏幕宽度:{screen_width}") 1. 2. 3. 4. 总结 本文介绍了四种常用的方法来获取屏幕宽度,包括使用screeninfo模块、pyautogui模块、tkinter模块和pygetwindow模块。根据实际需求,选择适合自己的方法来获取屏幕宽度。