简体   繁体   English

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

[英]How to get the size and location of the taskbar with PyGTK?

Is there any way to get the position and size of the taskbar on Windows with PyGTK? 有什么方法可以通过PyGTK在Windows上获取任务栏的位置和大小?

If not, is there at least a way to determine the free client area on a specific monitor? 如果不是,是否至少有一种方法可以确定特定监视器上的空闲客户区? (In other words, the area the taskbar does not occupy?) (换句话说,任务栏占用该区域吗?)

Slightly neater (but windows only) as this creates a dynamic pair of variables which you can then used to adjust the offset of your remaining code; 稍微整洁(仅适用于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])

Then, in the remainder of your code use these adjustments to refine your navigation clicks. 然后,在代码的其余部分中,使用这些调整来优化导航单击。 In my case I am moving around a window using pyautogui 就我而言,我正在使用pyautogui在窗口中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)

In your case you will want to create the top left corner of the new window at (or relative to) the co-ordinates of (x_adj,y_adj) 在您的情况下,您需要在(x_adj,y_adj)坐标处(或相对于该坐标)创建新窗口的左上角

You can maximize a window, and check its geometry after it was maximized. 您可以最大化窗口,并在最大化后检查其几何形状。 Something like this (works both on Windows and Linux): 这样的事情(在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

This is somewhat hackish, but I'm not sure if there is a portable way (without using Win32 API if you are on Windows) to do this. 这有点骇人听闻,但是我不确定是否有可移植的方法(如果您使用的是Windows,则不使用Win32 API)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM