Search code examples
pythonuser-interfacewxpythonwxwidgets

I've added style=wx.te_Multiline to my wx.textctrl item but my scroll bar is not working


I would like for my TextCtrl field to gain a vertical scroll as I write events out on it.

The code I have so far is;

sizer = wx.BoxSizer(wx.VERTICAL) #Create a vertical sizer

#Create our multiline console area          
self.term = wx.TextCtrl(self, -1, '',  style=wx.TE_MULTILINE) 

#Add our console to the sizer
sizer.Add(self.term, 5, wx.EXPAND | wx.TOP | wx.BOTTOM, 0) 

gs = wx.GridSizer(1, 3, 0, 0) #Define the grid layout in rows, columns

gs.AddMany([
    (wx.Button(self.panel, 3, 'Browse'), 0, wx.EXPAND),
    (wx.Button(self.panel, 1, 'RUN'), 0, wx.EXPAND),
    (wx.Button(self.panel, 2, 'QUIT'), 0, wx.EXPAND) ])

#Add our defined grid layout above to our sizer                 
sizer.Add(gs, 1, wx.EXPAND)

self.SetSizer(sizer) #Pass & show our sizer

I get a scoll bar, it however does not respond to mouse clicks. What am I doing wrong?


Solution

  • Those three buttons are children of self.panel, which is just hanging out in your frame, intercepting your mouse events. If you allow resizing, you'll see that the panel is not resized along with the buttons, but you can click on the portion of the TextCtrl that extends beyond it.

    You can either get rid of the panel entirely and make everything a child of the frame, or make gs the panel's sizer, and add the panel to your main sizer in place of gs:

        sizer.Add(self.term, 5, wx.EXPAND | wx.TOP | wx.BOTTOM, 0) 
    
        gs = wx.GridSizer(1, 3, 0, 0) #Define the grid layout in rows, columns
        gs.AddMany([
            (wx.Button(self.panel, 3, 'Browse'), 0, wx.EXPAND),
            (wx.Button(self.panel, 1, 'RUN'), 0, wx.EXPAND),
            (wx.Button(self.panel, 2, 'QUIT'), 0, wx.EXPAND) ])
    
        self.panel.SetSizer(gs)
    
        sizer.Add(self.panel, 1, wx.EXPAND) #Add our defined grid layout above to our sizer