簡體   English   中英

如何使用PyGTK獲取任務欄的大小和位置?

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

有什么方法可以通過PyGTK在Windows上獲取任務欄的位置和大小?

如果不是,是否至少有一種方法可以確定特定監視器上的空閑客戶區? (換句話說,任務欄占用該區域嗎?)

稍微整潔(僅適用於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在窗口中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)坐標處(或相對於該坐標)創建新窗口的左上角

您可以最大化窗口,並在最大化后檢查其幾何形狀。 這樣的事情(在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)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM