1

I have a Notebook in wxpython:

self.book = wx.Notebook(self, -1, style=0)
self.book.AddPage(self.book_a,_("a"))
self.book.AddPage(self.book_b,_("b"))

This code works fine. Evrything is as it should.

The thing is that I have later a condition if x==1: that if it's true I need to hide/disable book_b page (preferbly disable).

i wrote this code:

if  x==1:
    self.book_a.Hide()

but nothing happend. Then I tried:

if  x==1:
    self.book_a.Disable()

but also nothing happend.

If I do:

print self.book_a.Hide()
print self.book_a.Disable()

it returns

False
False

I know it means the operation faild and that why I don't see any change but I couldn't find in google or elsewhere when Hide() or Disable() return False.

Does anyone know what is the problem or in what cases Hide() or Disable() return false?

avi
  • 1,626
  • 3
  • 27
  • 45

1 Answers1

1

The wx.Notebook widget doesn't support disabling pages. The only workaround would be to check which tab is being clicked on and if it is "disabled", veto the event (EVT_NOTEBOOK_PAGE_CHANGING or EVT_NOTEBOOK_PAGE_CHANGED).

There is an alternative though. You can use the FlatNotebook widget or the AUI Notebook from wx.lib.agw (wx.aui's Notebook does not support this that I know of). They both support the the ability to disable a tab. There are examples of both of these widgets in the wxPython demo.

I have some examples of these controls here as well:

See also:

UPDATE - I just tried disabling a page. While it doesn't stop the user from clicking on the tab, it DOES disable all the controls on that page:

import wx

########################################################################
class TabPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        text = wx.TextCtrl(self)


########################################################################
class MainPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
        notebook = wx.Notebook(self)

        tab_one = TabPanel(notebook)
        notebook.AddPage(tab_one, "Tab One")

        tab_two = TabPanel(notebook)
        tab_two.Disable()
        notebook.AddPage(tab_two, "Tab Two")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)



########################################################################
class MainFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Notebooks")
        panel = MainPanel(self)

        self.Show()

if __name__ == '__main__':
    app = wx.App(False)
    frame = MainFrame()
    app.MainLoop()
Community
  • 1
  • 1
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • If it doesn't support this operation why is it possible to choose this function from the menu? it has docomntation and everything. – avi Jul 30 '15 at 15:19
  • What menu are you referring to? – Mike Driscoll Jul 30 '15 at 15:34
  • when I type `self.book_a.` a menu of avliable functions and their discription is up. `Hide()` and `Disable()` are there. So if these options are not avliable for notebook why does it let me see them? – avi Aug 02 '15 at 05:35
  • As I mentioned, `Disable` works, but it just disables the page's widgets. This widget inherits from `Window`, so it does have `Hide`, but I'm not sure if it necessarily works the way you want it to. – Mike Driscoll Aug 03 '15 at 13:06