Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找应用程序宽度和高度-交叉平台_Python_Height_Width_Frame - Fatal编程技术网

Python 查找应用程序宽度和高度-交叉平台

Python 查找应用程序宽度和高度-交叉平台,python,height,width,frame,Python,Height,Width,Frame,我正在寻找一种方法来找到指定的窗口尺寸(宽度和高度)。到目前为止,我一直在使用AutoIt函数,只需编写部分窗口/框架名称,它的工作方式与我所希望的一样。唯一的问题是,它只在MS Windows中工作。我需要它跨平台工作(windows和linux) 由于平台如此不同,因此需要有两个脚本,一个用于windows,另一个用于Linux。我不想依赖额外的程序(比如AutoIt)。我不希望它被“硬编码”在脚本中选择什么帧。我需要/希望它像AutoIt一样工作,通过指定帧名称/或其部分。多亏了yurib

我正在寻找一种方法来找到指定的窗口尺寸(宽度和高度)。到目前为止,我一直在使用AutoIt函数,只需编写部分窗口/框架名称,它的工作方式与我所希望的一样。唯一的问题是,它只在MS Windows中工作。我需要它跨平台工作(windows和linux)


由于平台如此不同,因此需要有两个脚本,一个用于windows,另一个用于Linux。我不想依赖额外的程序(比如AutoIt)。我不希望它被“硬编码”在脚本中选择什么帧。我需要/希望它像AutoIt一样工作,通过指定帧名称/或其部分。

多亏了yurib,我才知道如何在windows中实现这一点

import win32con
import win32gui

def inText(haystack, needle, n):
    parts= haystack.split(needle, n+1)
    if len(parts)<=n+1:
        return False
    if len(haystack)-len(parts[-1])-len(needle):
        return True

def isRealWindow(hWnd):
    '''Return True if given window is a real Windows application window.'''
    if not win32gui.IsWindowVisible(hWnd):
        return False
    if win32gui.GetParent(hWnd) != 0:
        return False
    hasNoOwner = win32gui.GetWindow(hWnd, win32con.GW_OWNER) == 0
    lExStyle = win32gui.GetWindowLong(hWnd, win32con.GWL_EXSTYLE)
    if (((lExStyle & win32con.WS_EX_TOOLWINDOW) == 0 and hasNoOwner)
      or ((lExStyle & win32con.WS_EX_APPWINDOW != 0) and not hasNoOwner)):
        if win32gui.GetWindowText(hWnd):
            return True
    return False

def getWindowSizes(text):
    '''Return a list of tuples (handler, (width, height)) for each real window.'''
    def callback(hWnd, extra):
        if not isRealWindow(hWnd):
            return
        title   = win32gui.GetWindowText(hWnd)
        rect    = win32gui.GetWindowRect(hWnd)
        isFrame = inText(title, text, 0)
        if(isFrame):
            windows.append((title, rect[2] - rect[0], rect[3] - rect[1], rect[0],rect[1]))
    windows = []
    win32gui.EnumWindows(callback, windows)
    return windows

def findWindow(text):
    window = getWindowSizes(text)
    name = window[0][0]
    w = window[0][1]
    h = window[0][2]
    x = window[0][3]
    y = window[0][4]

    return name,w,h,x,y
导入win32con
导入win32gui
def inText(干草堆,针,n):
零件=干草堆。分开(针,n+1)

如果len(零件)看一下@SLACKY:你所说的程序或框架尺寸是什么意思?这是你感兴趣的窗口吗(如尤里布建议的)?或者,您想确定的是屏幕分辨率吗?