Color of the border

I would like to customize a TextCtrl to be able to define the width
and color of the border.

Any hint would be appreciated.

wx doesn't provide that level of control over the borders of widgets. Something that people will sometimes do instead is to make a class that derives from wx.Panel and has a wx.TextCtrl on it with no border, and then draw the border however you want it in the panel's EVT_PAINT event handler.

···

On 9/15/09 11:23 AM, AB wrote:

I would like to customize a TextCtrl to be able to define the width
and color of the border.

--
Robin Dunn
Software Craftsman

Hi Robin,

Thanks for your quick tip.

I had to avoid sizers and instead used the EVT_SIZE.

It works like a charm.

You are the champion! :slight_smile:

AB

class myTextCtrl(wx.Panel):

def __init__(self,parent, id, caption, style=wx.NO_BORDER):

	wx.Panel.__init__(self, parent, id=-1,)

	self.ed = wx.TextCtrl(self, -1, "", style=wx.NO_BORDER)

	self.Bind(wx.EVT_PAINT, self.OnPaint)

	self.Bind(wx.EVT_SIZE,self.OnSize)

def OnSize(self, event):

	size = event.GetSize()

	self.ed.SetPosition((1,1))

	self.ed.SetSize((size.x-2,size.y-2))

	event.Skip()

def OnPaint(self, evt):

	dc = wx.BufferedPaintDC(self)

	dc.SetBackground(wx.Brush(wx.Colour(112,112,112)))

	dc.Clear()

def SetBackgroundColour(self,cor):

	self.ed.SetBackgroundColour(cor)

def SetForegroundColour(self,cor):

	self.ed.SetForegroundColour(cor)

def SetFont(self,font):

	self.ed.SetFont(font)
···

On Wed, Sep 16, 2009 at 1:35 AM, Robin Dunn robin@alldunn.com wrote:

On 9/15/09 11:23 AM, AB wrote:

I would like to customize a TextCtrl to be able to define the width

and color of the border.

wx doesn’t provide that level of control over the borders of widgets.

Something that people will sometimes do instead is to make a class that

derives from wx.Panel and has a wx.TextCtrl on it with no border, and

then draw the border however you want it in the panel’s EVT_PAINT event

handler.

Robin Dunn

Software Craftsman

http://wxPython.org