= How to create a static text (Phoenix) = '''Keywords :''' Static text. <<TableOfContents>> -------- = Introduction : = A {{{wx.StaticText}}} widget displays one or more lines of read-only text. '''{{{wx.StaticText styles :}}}''' * wx.ALIGN_RIGHT * wx.ALIGN_LEFT * wx.ALIGN_CENTER / wx.ALIGN_CENTRE * wx.ST_NO_AUTORESIZE ||||<style="text-align:center;">'''{{{wx.StaticText methods}}}''' || ||<#d0d0d0>{{{Wrap(int width)}}} ||<#d0d0d0>if possible set each line of text to width pixels. if width is negative, no wrapping is done. || (info by '''ZetCode / Jan Bodnar'''). -------- = Demonstrating : = __'''''Tested''' py3.x, wx4.x and Win10. ''__ Are you ready to use some samples ? ;) Test, modify, correct, complete, improve and share your discoveries ! (!) -------- == Sample one == {{attachment:img_sample_one.png}} {{{#!python # sample_one.py """ Author : Jan Bodnar Website : zetcode.com """ import wx # class Frame # class MyApp #--------------------------------------------------------------------------- lyrics1 = '''I'm giving up the ghost of love in the shadows cast on devotion She is the one that I adore creed of my silent suffocation Break this bittersweet spell on me lost in the arms of destiny''' lyrics2 = '''There is something in the way You're always somewhere else Feelings have deserted me To a point of no return I don't believe in God But I pray for you''' #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(275, 350)) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO)) #------------ panel = wx.Panel(self, -1) wx.StaticText(panel, -1, lyrics1, (45, 25), style=wx.ALIGN_CENTRE) wx.StaticText(panel, -1, lyrics2, (45, 190), style=wx.ALIGN_CENTRE) #------------ self.Centre() #--------------------------------------------------------------------------- class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'wx.StaticText') frame.Show(True) self.SetTopWindow(frame) return True #--------------------------------------------------------------------------- app = MyApp(0) app.MainLoop() }}} -------- == Sample two == {{attachment:img_sample_two.png}} {{{#!python # sample_two.py """ Link : https://maku77.github.io/python/wxpython/statictext.html """ import wx # class Frame # class MyApp #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(300, 300)) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO)) #------------ # Create widgets. panel = wx.Panel(self) # Basic label. label1 = wx.StaticText(panel, -1, 'Basic label') # Left aligned label. label2 = wx.StaticText(panel, -1, 'Left aligned') label2.SetBackgroundColour('green') # Center aligned label. label3 = wx.StaticText(panel, -1, 'Center aligned', style=wx.ALIGN_CENTER) label3.SetBackgroundColour('green') # Right aligned label. label4 = wx.StaticText(panel, -1, 'Right aligned', style=wx.ALIGN_RIGHT) label4.SetBackgroundColour('green') # Left aligned multiple lines label. label5 = wx.StaticText(panel, -1, 'Left aligned\nmultiple\nlines text') label5.SetBackgroundColour('cyan') # Center aligned multiple lines label. label6 = wx.StaticText(panel, -1, 'Center aligned\n' 'multiple\nlines text', style=wx.ALIGN_CENTER) label6.SetBackgroundColour('cyan') # Center aligned multiple lines label. label7 = wx.StaticText(panel, -1, 'Right aligned\n' 'multiple\nlines text', style=wx.ALIGN_RIGHT) label7.SetBackgroundColour('cyan') # Set sizer. sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(label1, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label2, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label3, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label4, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label5, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label6, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) sizer.Add(label7, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) panel.SetSizer(sizer) #------------ self.Centre() #--------------------------------------------------------------------------- class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'wx.StaticText') frame.Show(True) self.SetTopWindow(frame) return True #--------------------------------------------------------------------------- app = MyApp(0) app.MainLoop() }}} -------- = Download source = [[attachment:source.zip]] -------- = Additional Information = '''Link :''' - - - - - https://wiki.wxpython.org/TitleIndex https://docs.wxpython.org/ -------- = Thanks to = Jan Bodnar (sample_one.py coding), maku77 (sample_two.py coding), the wxPython community... -------- = About this page = Date(d/m/y) Person (bot) Comments : 28/12/20 - Ecco (Created page for wxPython Phoenix). -------- = Comments = - blah, blah, blah....