wxPython - Tooltips for notebook tabs

399 Views Asked by At

I'm creating a GUI using wxPython that uses the wx.Notebook widget. Since I removed the labels on the Notebook tabs for design purposes, I would like to add tooltips for each tab individually that show the tab's purpose.

I thought I could use the AddPage() method of the Notebook class. But it only returns bool values, so that I cannot use the SetToolTip() method for either tab. How would I go about doing that?

1

There are 1 best solutions below

1
Mike Driscoll On BEST ANSWER

This is not something that is built-in to the wx.Notebook widget. You could probably do it yourself by binding to wx.EVT_MOTION and checking you mouse's position to determine when to set a tooltip.

The AUINotebook might be a better choice since it has a TabHitTest method. Someone on the wxPython group mentioned a way to add tooltips to it here: http://wxpython-users.1045709.n5.nabble.com/setting-a-tooltip-on-auinotebook-tab-td5548750.html

Here's the code they ended up using in the mouse over event handler:

def OnMouseOver(self, evt):
    """ mouse over on a tab """

    desc = None
    n    = self.GetSelection()
    if n != -1:
        page_info = self._tabs.GetPage(n)
        ctrl, ctrl_idx = self.FindTab(page_info.window)
        if ctrl:
            ctrl.SetToolTipString(desc)