鼠标在wx.grid wxpython中悬停在单元格上时的工具提示消息

鼠标在wx.grid wxpython中悬停在单元格上时的工具提示消息,grid,wxpython,tooltip,mousehover,Grid,Wxpython,Tooltip,Mousehover,我有一个wx.grid表格,我想在悬停在单元格上时设置工具提示,我尝试了Mike Driscoll下面的建议,它可以工作,但我不能再使用鼠标拖动选择多个单元格,它允许我最多选择一个单元格,请帮助: self.grid_area.GetGridWindow().Bind(wx.EVT_MOTION, self.onMouseOver) def onMouseOver(self, event): ''' Method to calculate where t

我有一个wx.grid表格,我想在悬停在单元格上时设置工具提示,我尝试了Mike Driscoll下面的建议,它可以工作,但我不能再使用鼠标拖动选择多个单元格,它允许我最多选择一个单元格,请帮助:

self.grid_area.GetGridWindow().Bind(wx.EVT_MOTION, self.onMouseOver)

    def onMouseOver(self, event):
        '''
        Method to calculate where the mouse is pointing and
        then set the tooltip dynamically.
        '''

        # Use CalcUnscrolledPosition() to get the mouse position
        # within the
        # entire grid including what's offscreen
        x, y = self.grid_area.CalcUnscrolledPosition(event.GetX(),event.GetY())

        coords = self.grid_area.XYToCell(x, y)
        # you only need these if you need the value in the cell
        row = coords[0]
        col = coords[1]
        if self.grid_area.GetCellValue(row, col):
            if self.grid_area.GetCellValue(row, col) == "ABC":
                event.GetEventObject().SetToolTipString("Code is abc")
            elif self.grid_area.GetCellValue(row, col) == "XYZ":
                event.GetEventObject().SetToolTipString("code is xyz")
            else:
                event.GetEventObject().SetToolTipString("Unknown code")   

好的,我找到了解决方案,我必须跳过事件:

def onMouseOver(self, event):
        '''
        Method to calculate where the mouse is pointing and
        then set the tooltip dynamically.
        '''

        # Use CalcUnscrolledPosition() to get the mouse position
        # within the
        # entire grid including what's offscreen
        x, y = self.grid_area.CalcUnscrolledPosition(event.GetX(),event.GetY())

        coords = self.grid_area.XYToCell(x, y)
        # you only need these if you need the value in the cell
        row = coords[0]
        col = coords[1]
        if self.grid_area.GetCellValue(row, col):
            if self.grid_area.GetCellValue(row, col) == "ABC":
                event.GetEventObject().SetToolTipString("Code is abc")
            elif self.grid_area.GetCellValue(row, col) == "XYZ":
                event.GetEventObject().SetToolTipString("code is xyz")
            else:
                event.GetEventObject().SetToolTipString("Unknown code")   
        event.Skip()
谢谢 最诚挚的问候

@GreenAsJade 由于声誉问题,我无法发表评论,所以我在这里问你的问题

为什么:出了什么问题,这是如何解决的

如果检查事件Hanlder和@alwbtc的事件处理程序之间的差异,则唯一的区别是event.Skip()

每当wx.EVT_xx与代码中的自定义方法绑定时,wxpython都会覆盖默认定义。因此,事件处理以onMouseOver结束。event.Skip()将事件传播到wxptyhon的_core,允许它执行默认事件处理程序


希望这能回答你的问题

如果有人能评论一下原因,那就太好了:出了什么问题,这是怎么解决的?