Notebook pages tab customization

I want to enlarge the tab section (where the tabs of all the pages are there), and add custom background colour to it. Also when a tab is selected, different colour for it.

How can I do it?

Hi Tanmay,

You can do that using wx.aui.AuiNotebook.
To enlarge the tab section, change TabCtrlHeight.
To change the background colour of the selected tab, use ActiveTabCtrl.SetActiveColour.

see also:
https://docs.wxpython.org/wx.aui.AuiNotebook.html#property-summary-properties-summary

Thanks for your reply!

ActiveTabCtrl.SetActiveColour is throwing ‘invalid function’ error.

However wx.aui.AuiSimpleTabArt.SetActiveColour worked.
Below is the code snippet :-

        self.nb = wx.aui.AuiNotebook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.aui.AUI_NB_TAB_FIXED_WIDTH)

        # self._art = self.nb.GetArtProvider()

        self._art = wx.aui.AuiSimpleTabArt()

        self.nb.SetArtProvider(self._art)

        self._art.SetActiveColour(wx.Colour((204,0,0)))

        self._art.SetColour(wx.Colour((17, 85, 102)))

        self._art.SetNormalFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))

        self._art.SetSelectedFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))

By this I am able to change the colour of active and inactive tabs and change the font for inactive tabs.

But when I apply the font change for active tab (SetSelectedFont) it isn’t working. Still getting the smaller font.
How can we solve that?

Also, I want the tabs to take up the whole horizontal space of the tab section (Say there are 3 tabs, each should take 33% of the horizontal space).

I also want padding in each tab.

All these should be responsive, i.e. should adjust accordingly with the screen size

How can we do these things?

One more thing, due to some reason, wx.aui.AuiDefaultTabArt and wx.aui.AuiTabArt doesn’t work.
Why?

Maybe it depends on wx version. (I tested with 4.2.0).
ActiveTabCtrl returns wx.aui.AuiTabCtrl class which is a subclass of wx.aui.AuiTabContainer.
It has SetActiveColour method, but as far as I tested, SetActiveColour works only for tabs with bottom style. So, I think your solution seems better and more general. :smiley:

There is also a SetSelectedFont method, but I found that moving the tab focus reverts to the default font. One workaround would be to use EVT_AUNOTEBOOK_PAGE_CHANGED event:

import wx
from wx import aui

class Book(aui.AuiNotebook):
    def __init__(self, parent):
        super().__init__(parent,
            style=(aui.AUI_NB_DEFAULT_STYLE
                 | aui.AUI_NB_BOTTOM
                 | aui.AUI_NB_TAB_MOVE
                 )
        )
        for x in range(5):
            win = wx.TextCtrl(self)
            self.AddPage(win, "page {}".format(x))

        self.TabCtrlHeight = 32
        font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL)

        self.ActiveTabCtrl.SetActiveColour('blue')
        
        ## self.ActiveTabCtrl.SetSelectedFont(font) -> not good...

        def on_page_changed(evt):
            self.ActiveTabCtrl.SetSelectedFont(font)
        self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, on_page_changed)

if __name__ == "__main__":
    app = wx.App()
    frm = wx.Frame(None)
    frm.nb = Book(frm)
    frm.Show()
    app.MainLoop()

image

I have no idea about the rest of your questions…

Sadly, this isn’t working…
Still the same result…The active tab has the default font only

Have you tried wx 4.2.0?
I’m sure you can overcome the sadness.

Yeah, that is what I am using, wxPython version 4.2.0