I have a problem with tree control and i don't know how to solve it, maybe someone can help me. What i'm trying to do is display widgets in a staticbox plus a help text when i select different items in a tree.
For example when i select item1 in a a tree control i want to display two checkboxes in Demo staticbox control. When i select item2 display only two radio buttons in the same control and so on. Plus for every item selected in the tree control display some help text in text control. If someone can help with that or give me an idea to start i will be very grateful.
Here is the demo code (it's not very organized but it's only for testing):

import wx


class DemoFrame(wx.Frame):
    
    def __init__(self, parent, id):
        
        wx.Frame.__init__(self, parent, id, 'Demo', size=(600, 400), pos=(300,300))
        
        self.panel1=wx.Panel (self, -1)
        self.panel1.SetBackgroundColour ("white")
        self.DoLayout ()
        

    
    def DoLayout (self):
        
        #sizers
        mainsizer = wx.BoxSizer(wx.VERTICAL)
        panelsizer = wx.BoxSizer(wx.VERTICAL)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.VERTICAL)
        
####################################################################        
        #create splitter windows
        self.splitter = wx.SplitterWindow(self, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
        self.splitter2 = wx.SplitterWindow(self.splitter, -1, style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
        
        self.mainpanel = wx.Panel(self.splitter, -1)
        self.leftpanel2 = wx.Panel(self.splitter2, -1, style=wx.WANTS_CHARS)
        self.mainpanel.SetBackgroundColour ("white")
 
####################################################################
        
        #create tree control
        self.tree = wx.TreeCtrl(self.mainpanel, -1, wx.Point(0, 0), wx.Size(160, 250),
                            wx.TR_DEFAULT_STYLE | wx.NO_BORDER)
        self.root = self.tree.AddRoot("Root Demo Item")
        item1 = self.tree.AppendItem (self.root, "Item1",0)
        item2 = self.tree.AppendItem (self.root, "Item2",0)
        self.tree.Expand(self.root)
        
###################################################################################
        #add other widgets
        self.help = wx.TextCtrl(self.splitter2, -1,
                               style = wx.TE_MULTILINE|wx.TE_READONLY | wx.HSCROLL)
        staticboxstyles = wx.StaticBox(self.leftpanel2, -1, "Demo", size=(485, 240))
        self.splitter2.SetBackgroundColour (wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
#################################################################################        
        #add widgets to sizers
        panelsizer.Add(self.splitter, 1, wx.EXPAND, 0)
        sizer1.Add(self.tree, 1, wx.EXPAND)
        sizer2.Add(staticboxstyles, 1, wx.BOTTOM|wx.EXPAND|wx.ALIGN_BOTTOM, 60 )
        
    
########################################################################################        
        #set sizers
        self.mainpanel.SetSizer(sizer1)
        self.leftpanel2.SetSizer(sizer2)
        self.SetSizer(panelsizer)
        mainsizer.Layout()
        self.Layout()

#######################################################################
     
        #set splitters
        self.splitter.SplitVertically(self.mainpanel, self.splitter2, 300)
        self.splitter2.SplitHorizontally(self.leftpanel2, self.help, -160)
        self.splitter.SetSashPosition (200)
        

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = DemoFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()

Recommended Answers

All 5 Replies

Try what ? I'm sure your blog it's very interesting but i don't see the connection with my problem

This might help:

import wx


class DemoFrame(wx.Frame):
    
    def __init__(self, parent, id):
        
        wx.Frame.__init__(self, parent, id, 'Demo', size=(600, 400), pos=(300,300))
        
        # make the widgets ...
        self.panel1=wx.Panel (self, -1)
        self.panel1.SetBackgroundColour ("white")

        # create splitter windows
        self.splitter = wx.SplitterWindow(self,
            style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
        self.splitter2 = wx.SplitterWindow(self.splitter, -1,
            style=wx.CLIP_CHILDREN | wx.SP_LIVE_UPDATE | wx.SP_3D)
        self.mainpanel = wx.Panel(self.splitter, -1)
        self.leftpanel2 = wx.Panel(self.splitter2, -1, style=wx.WANTS_CHARS)
        self.mainpanel.SetBackgroundColour ("white")
        self.splitter2.SetBackgroundColour (wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))

        # create tree control
        self.tree = wx.TreeCtrl(self.mainpanel, -1, wx.Point(0, 0), wx.Size(160, 250),
            wx.TR_DEFAULT_STYLE | wx.NO_BORDER)
        self.root = self.tree.AddRoot("Root Demo Item")
        item1 = self.tree.AppendItem (self.root, "Item1",0)
        item2 = self.tree.AppendItem (self.root, "Item2",0)
        self.tree.Expand(self.root)

        # add other widgets
        self.help = wx.TextCtrl(self.splitter2, -1,
            style = wx.TE_MULTILINE|wx.TE_READONLY | wx.HSCROLL)
        self.staticboxstyles = wx.StaticBox(self.leftpanel2, -1, "Demo", size=(485, 240))
        
        self.DoLayout ()
        
        # bind tree action
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)

    
    def DoLayout (self):
        
        # sizers
        mainsizer = wx.BoxSizer(wx.VERTICAL)
        panelsizer = wx.BoxSizer(wx.VERTICAL)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.VERTICAL)
      
        # add widgets to sizers
        panelsizer.Add(self.splitter, 1, wx.EXPAND, 0)
        sizer1.Add(self.tree, 1, wx.EXPAND)
        sizer2.Add(self.staticboxstyles, 1, wx.BOTTOM|wx.EXPAND|wx.ALIGN_BOTTOM, 60 )
    
        # set sizers
        self.mainpanel.SetSizer(sizer1)
        self.leftpanel2.SetSizer(sizer2)
        self.SetSizer(panelsizer)
        mainsizer.Layout()
        self.Layout()

        # set splitters
        self.splitter.SplitVertically(self.mainpanel, self.splitter2, 300)
        self.splitter2.SplitHorizontally(self.leftpanel2, self.help, -160)
        self.splitter.SetSashPosition (200)


    def OnSelChanged(self, event):
        self.item = event.GetItem()
        select = self.tree.GetItemText(self.item)
        if self.item:
            # test (create your help string here)
            str1 = "Selected item = %s\n" % select
            self.help.SetValue(str1)
        if select == 'Item1':
            # test (create your check boxes instead)
            self.staticbox_check = wx.StaticBox(self.leftpanel2, -1, "Check",
                pos=(10, 20), size=(300, 100))
        if select == 'Item2':
            # test (create your radio buttons instead)
            self.staticbox_check = wx.StaticBox(self.leftpanel2, -1, "Radio",
                pos=(10, 20), size=(300, 100))
        

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = DemoFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()

Note: My opinion about blogs is mostly paintspray on the wall to make person important.

Thank you bumsfeld for trying to help me. The problem is not to create checkboxes or radio buttons or whatever when i select a tree item but removing checkboxes or other controls when select other tree item. Ok, i create checkboxes when i select item1 but those checkboxes will not be removed when i select item2, for example. That's the problem. Something like wxpython demo. Unfortunately i'm not that advanced in wxpython to analyze wxpython demo and find the solution

To hide or show a wxPython widget you can use something like ...

button1.Hide()  # make button invisible
button1.Show()  # show it again
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.