如何用PyGTK获取任务栏的大小和位置?

1 投票
2 回答
1259 浏览
提问于 2025-04-16 16:19

有没有办法用PyGTK获取Windows任务栏的位置和大小呢?

如果没有,那有没有办法确定某个显示器上可用的客户区域?也就是说,任务栏占用的区域?

2 个回答

0

这个方法稍微整洁一点(但只适用于Windows),因为它会创建一对动态变量,你可以用它们来调整你剩下代码的偏移量。

import win32gui

#discover where top left corner of active screen is
#return is a dictionary list of keys and values
monitors = win32api.EnumDisplayMonitors()
display1 = win32api.GetMonitorInfo(monitors[0][0])

#from the Work key, select the first and second values
x_adj=(display1['Work'][0])
y_adj=(display1['Work'][1])

然后,在你代码的其他部分,使用这些调整来优化你的导航点击。在我的例子中,我是通过 pyautogui 来移动窗口。

import pyautogui

#just move the mouse to a position
pyautogui.moveTo(x=103+x_adj, y=235+y_adj)

#move and click the mouse
pyautogui.click(x=103+x_adj, y=235+y_adj)

在你的情况下,你需要把新窗口的左上角设置在(或相对于)坐标 (x_adj,y_adj) 的位置。

0

你可以把一个窗口最大化,然后在它最大化之后检查一下它的大小和位置。像这样做(在Windows和Linux上都可以用):

import gtk

size = (10, 10)
def expose(widget, *args):
    global size
    size = widget.get_size()
    if size != (10, 10):
        gtk.main_quit()

win = gtk.Window()
win.resize(*size)
win.connect('expose-event', expose)
win.show()
win.maximize()
gtk.main()
print size

这有点像是变通的方法,但我不太确定有没有其他更通用的方式(如果你在Windows上,不使用Win32 API)来做到这一点。

撰写回答