Cannot use Widgets in wx.Listbook

Hey, so i want to creat a settings menu.

For that purpose i use a wx.Listbook and fill it up with panels. The panels are all seperate classes. The change between the panel works. But when i put some widgets on the panels like Buttons or checkboxes, they are not usable. I cannot click them or anything. I have a minimum viable example here that might help to understand the problen.

# -*- coding: utf-8 -*-
"""
Created on Tue Jul 13 15:54:51 2021

@author: Odatas
"""

import wx
import wx.lib.scrolledpanel as scrolled

#First Panel
class settingsConnection(wx.ScrolledWindow):

    def __init__(self,parent,size):
        wx.ScrolledWindow.__init__(self,parent=parent,size=size)
        self.topLevelSizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.topLevelSizer)
        self.infoText = wx.StaticText(self
                                      ,label="I'm Panel settingsConnection\n\nUnder construction."
                                      ,style=wx.ALIGN_CENTRE_HORIZONTAL)
        self.topLevelSizer.Add(self.infoText)

#Second Panel
class settingsGeneral(wx.Panel):

    def __init__(self,parent,size):
        wx.Panel.__init__(self,parent=parent,size=size)
        self.topLevelSizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.topLevelSizer)
        self.infoText = wx.StaticText(self
                                      ,label="I'm  Panel settingsGeneral\n\nUnder construction."
                                      ,style=wx.ALIGN_CENTRE_HORIZONTAL)
        self.topLevelSizer.Add(self.infoText)

#Third Panel
class settingsABC(wx.Panel):

    def __init__(self,parent,size):
        wx.Panel.__init__(self,parent=parent,size=size)
        self.topLevelSizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.topLevelSizer)

        self.firstSizer = wx.BoxSizer(wx.VERTICAL)
        self.secondSizer = wx.BoxSizer(wx.VERTICAL)
        self.thridSizer = wx.BoxSizer(wx.VERTICAL)

        self.autoStartCheckBox=wx.CheckBox(self, label="Button")
        self.autoStartCheckBox.SetValue(True)

        self.testButton = wx.Button(self,label="Test")

        self.topLevelSizer.Add(self.autoStartCheckBox)
        self.topLevelSizer.Add(self.testButton)

        self.topLevelSizer.Layout()
        self.Fit()

#The main frame that holds all the panels
class settingsWindow(wx.Frame):

    FLAG_KILL_ME = False


    def __init__(self,parent):
        wx.Frame.__init__(self,parent=parent.frame,size=(1000,800),style= wx.CAPTION | wx.CLOSE_BOX |wx.STAY_ON_TOP|wx.FRAME_NO_TASKBAR)

        self.Bind(wx.EVT_CLOSE,self.onQuit)
        # self.Bind(wx.EVT_LIST_ITEM_FOCUSED,self.onFocusChange)
        self.parent=parent
        self.panel = wx.Panel(self)
        self.panelSize=(800,700)
        self.panel.SetBackgroundColour(wx.Colour(255,255,255))
        #Contains Everything Level 0
        self.topLevelSizer = wx.BoxSizer(wx.VERTICAL)
        #Contains Top Part Level 01
        self.windowSizer=wx.BoxSizer(wx.HORIZONTAL)
        #Contains Bottom part Level 01
        self.buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        #Contains Widgets for Mainpart
        self.widgetSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.panel.SetSizer(self.topLevelSizer)
        self.topLevelSizer.Add(self.windowSizer)
        self.topLevelSizer.Add(self.buttonSizer)
        self.windowSizer.Add(self.widgetSizer)

        self.settingsBook = wx.Listbook(self.panel)
        self.widgetSizer.Add(self.settingsBook)

        self.settingsBook.InsertPage(0, settingsGeneral(self,self.panelSize), "Settins")
        self.settingsBook.InsertPage(1, settingsConnection(self,self.panelSize), "Connections")
        self.settingsBook.InsertPage(2, settingsABC(self,self.panelSize), "ABC")
        self.panel.Fit()






        self.Centre()
        self.Show()

        while self.FLAG_KILL_ME is False:
            wx.GetApp().Yield()


        try:
            self.Destroy()
        except Exception as e:
            pass

    def onQuit(self,event=None):
        self.FLAG_KILL_ME = True
        self.Hide()



class Testapp(wx.App):

    def __init__(self,redirect=False,filename=None):


        wx.App.__init__(self,redirect,filename)
        self.frame=wx.Frame(None,title="Test")
        self.panel=wx.Panel(self.frame,size=(1000,1000))
        self.TopLevelSizer=wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(self.TopLevelSizer)
        self.settingsButton = wx.Button(self.panel,label="Settings")
        self.TopLevelSizer.Add(self.settingsButton)
        self.settingsButton.Bind(wx.EVT_BUTTON, self.openSettings)
        self.frame.Show()

    def openSettings(self,event=None):
        settingsWindow(self)



if __name__=='__main__':
    app=Testapp()
    app.MainLoop()

try to go from simple to less simple, not from complex to void :upside_down_face:

Thanks for your help but could you be a bit more specific? I dont understand exactly what you mean.

Hi,

Simplification always helps you guess the cause of the problem.
You can remove even more irrelevant sizers and panels.

Anyway, this kind of problem is due to bad parents. In your case, the settingsABC object must have settingsBook as the parent. So, modify as follows.

-        self.settingsBook.InsertPage(2, settingsABC(self,self.panelSize), "ABC")
+        self.settingsBook.InsertPage(2, settingsABC(self.settingsBook,self.panelSize), "ABC")
1 Like

Thanks. That indeed worked.

I also found another way in the meantime. I just instanciate the widgets directly from the class instead of creating new classes for every page.

Thanks. It worked positively