TextCtrl borders disappearing

Hi,

I have an issue with disappearing borders of TextCtrl widgets if I use
them inside a StaticBox and set a background colour. To reproduce the
problem run the following code, then disable and enable the text
controls using the radio buttons. I use wxPython 2.9.4.0 win32.

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(320, 200))

        self.SetMinSize((320, 200))

self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENU))

        # panel for widgets
        self.panel = wx.Panel(self)

        # box
        self.box = wx.StaticBox(self.panel, wx.ID_ANY, "Text
Controls")
        self.box_sizer = wx.StaticBoxSizer(self.box , wx.VERTICAL)
        self.box_inner_sizer = wx.FlexGridSizer(1, 3, vgap=10,
hgap=10)

        self.text1 = wx.TextCtrl(self.panel, wx.ID_ANY, "text1",
size=(60, -1))
        self.text2 = wx.TextCtrl(self.panel, wx.ID_ANY, "text2",
size=(60, -1))
        self.text3 = wx.TextCtrl(self.panel, wx.ID_ANY, "text3",
size=(60, -1))
        self.radio_on = wx.RadioButton(self.panel, wx.ID_ANY, "on",
style = wx.RB_GROUP)
        self.radio_off = wx.RadioButton(self.panel, wx.ID_ANY, "off")

        self.box_inner_sizer.Add(self.text1, 0, wx.ALIGN_CENTER |
wx.EXPAND, 5)
        self.box_inner_sizer.Add(self.text2, 0, wx.ALIGN_CENTER |
wx.EXPAND, 5)
        self.box_inner_sizer.Add(self.text3, 0, wx.ALIGN_CENTER |
wx.EXPAND, 5)

        self.box_sizer.Add(self.box_inner_sizer, 0, wx.ALIGN_CENTER |
wx.EXPAND, 5)
        self.panel_sizer = wx.BoxSizer(wx.VERTICAL)
        self.panel_sizer.Add(self.box_sizer, 0, wx.ALIGN_CENTER |
wx.EXPAND)
        self.panel_sizer.Add(self.radio_on, 0,
wx.ALIGN_CENTER_VERTICAL, 5)
        self.panel_sizer.Add(self.radio_off, 0,
wx.ALIGN_CENTER_VERTICAL, 5)

        self.panel.SetSizer(self.panel_sizer)
        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
        self.main_sizer.Add(self.panel, 0, wx.EXPAND)

        # Set events.

        self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioOn, self.radio_on)
        self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioOff, self.radio_off)

        self.SetSizer(self.main_sizer)
        self.SetAutoLayout(1)
        self.Show(True)

    def OnRadioOn(self, e):
        self.text1.Enable()
        self.text2.Enable()
        self.text3.Enable()

    def OnRadioOff(self, e):
        self.text1.Disable()
        self.text2.Disable()
        self.text3.Disable()

app = wx.App(False)
frame = MainWindow(None, "Test")
app.MainLoop()

Sorry, I did not properly include my code as an attachment. So again…

test.py (2.38 KB)

Raphael Mameghani wrote:

Hi,

I have an issue with disappearing borders of TextCtrl widgets if I use
them inside a StaticBox and set a background colour. To reproduce the
problem run the following code, then disable and enable the text
controls using the radio buttons. I use wxPython 2.9.4.0 win32.

Looks like maybe the staticbox is clipping too closely to the textctrls, or something like that. Adding a self.panel.Refresh() after the Enables or Disables will take care of it.

···

--
Robin Dunn
Software Craftsman

The solution is OK for me, but not perfect, since Refresh() causes my application to flicker (which has a larger panel than the example I posted what makes the flickering more prominent). If I try to avoid this via “self.SetDoubleBuffered(True)” just after the line in which the background colour is set, the static box is empty - no text controls :-(. The text controls are back again if I remove the line setting the background colour, so I assume there is an issue with static boxes in combination with the background colour. BTW, already in my original code the border problem disappears if I do not modify the background colour.

Raphael

···

Am Mittwoch, 5. Juni 2013 19:04:29 UTC+2 schrieb Robin Dunn:

Raphael Mameghani wrote:

Hi,

I have an issue with disappearing borders of TextCtrl widgets if I use

them inside a StaticBox and set a background colour. To reproduce the

problem run the following code, then disable and enable the text

controls using the radio buttons. I use wxPython 2.9.4.0 win32.

Looks like maybe the staticbox is clipping too closely to the textctrls,
or something like that. Adding a self.panel.Refresh() after the Enables
or Disables will take care of it.

Raphael Mameghani wrote:

The solution is OK for me, but not perfect, since Refresh() causes my
application to flicker (which has a larger panel than the example I
posted what makes the flickering more prominent). If I try to avoid this
via "self.SetDoubleBuffered(True)" just after the line in which the
background colour is set, the static box is empty - no text controls
:-(. The text controls are back again if I remove the line setting the
background colour, so I assume there is an issue with static boxes in
combination with the background colour. BTW, already in my original code
the border problem disappears if I do not modify the background colour.

You may want to try making the items within the static box be its children instead of its siblings.

···

--
Robin Dunn
Software Craftsman