[wxPython] wxStaticText

Greg Krohn greg at invalid.invalid
Sat Jul 3 14:46:03 EDT 2004


Bernd Kaiser wrote:
> I mean selectable, so you can select the text with the mouse.

I would use a TextCtrl. You can set it's style to read-only if all you 
really want is selectable text which can't be edited by the user. Or if 
you DO want it to resemble a StaticText, also remove the border style 
and change the background Colour. The only apparent downside of this 
approach is you still get a blinking cursor (at least on WinXP).


import wx

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Test")

panel = wx.Panel(frame, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(sizer)

label1 = wx.TextCtrl(panel, -1, "Read-only", style=wx.TE_READONLY)
sizer.Add(label1, 0, flag=wx.EXPAND|wx.ALL, border=10)

label2 = wx.TextCtrl(panel, -1,
                      "Read-only + No Border + Change BG Color",
                      style=wx.TE_READONLY|wx.NO_BORDER)
label2.SetBackgroundColour(panel.GetBackgroundColour())
sizer.Add(label2, 0, flag=wx.EXPAND|wx.ALL, border=10)

frame.Show(True)
app.MainLoop()


hth,
greg



More information about the Python-list mailing list