【问题标题】:PyGTK: move custom build tooltip windowPyGTK:移动自定义构建工具提示窗口
【发布时间】:2012-05-23 07:37:27
【问题描述】:

我已经构建了带有 matplotlib 图形的 PyGTK 应用程序。我也想使用自定义构建的工具提示窗口。工具提示值根据鼠标在图形上的位置而变化。

我的问题是,我无法将工具提示窗口移动到鼠标旁边,因为我不知道如何在屏幕上获取鼠标位置

这是我的剥离代码:

def figPrepare(self):   #initialize graph
        #figure preparation stuff

        #custom tooltip window
        tooltip = gtk.Window(gtk.WINDOW_POPUP)
        lbl = gtk.Label()
        tooltip.add(lbl)
        lbl.show()

        figure.canvas.set_tooltip_window(tooltip)
        figure.canvas.props.has_tooltip = True
        #events
        figure.canvas.mpl_connect('figure_enter_event',lambda w: tooltip.show())
        figure.canvas.mpl_connect('motion_notify_event',lambda w: self.updateTooltip(tooltip, lbl))
        figure.canvas.mpl_connect('figure_leave_event',lambda w: tooltip.hide())


    def updateTooltip(self, win, lbl):
        lbl.set_text(str(time.time()))
        win.move(w.x, w.y)

此代码移动工具提示窗口,但值基于 matplotlib 图形,而不是屏幕中的绝对位置。

有人能告诉我如何将工具提示窗口移动到鼠标指针旁边吗?

【问题讨论】:

    标签: python matplotlib pygtk


    【解决方案1】:

    我找到了解决办法:

    def updateTooltip(self, win, lbl):
        lbl.set_text(str(time.time()))
        x, y, mods = win.get_screen().get_root_window().get_pointer()   #this gets absolute mouse possition on screen
        win.move(x+15, y+10)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-16
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-04
      • 2013-06-23
      • 2011-09-28
      相关资源
      最近更新 更多