【问题标题】:How to get the size and location of the taskbar with PyGTK?如何使用 PyGTK 获取任务栏的大小和位置?
【发布时间】:2011-04-24 05:01:40
【问题描述】:

有什么方法可以用 PyGTK 获取 Windows 上任务栏的位置和大小?

如果没有,是否至少有一种方法可以确定特定显示器上的空闲客户区? (也就是说,任务栏占据的区域?)

【问题讨论】:

  • 你为什么需要这个?我的意思是,无论如何,您是在自己的窗口中绘图,即使它覆盖了除任务栏之外的整个屏幕。您可以随时检查自己的窗口大小,不是吗?
  • @abbot:我想创建一个相对于任务栏位置定位的窗口。

标签: python pygtk taskbar area


【解决方案1】:

您可以最大化窗口,并在最大化后检查其几何形状。像这样的东西(适用于 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)来执行此操作。

【讨论】:

    【解决方案2】:

    稍微整洁(但仅限于 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) 的坐标处(或相对于)创建新窗口的左上角

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多