Skip to content
Related Articles

Related Articles

Improve Article

wxPython – Add text in window

  • Last Updated : 10 May, 2020
Geek Week

In this particular article we are going to know, how we can add text to a window using wxPython. This can be done using wx.StaticText class. StaticText() constructor controls displays one or more lines of read-only text.

Syntax :

wx.StaticText(self, parent, id=ID_ANY, label=””, pos=DefaultPosition,
                    size=DefaultSize, style=0, name=StaticTextNameStr)

Parameters :

ParameterInput TypeDescription
parentwx.WindowParent window. Should not be None.
idwx.WindowIDControl identifier. A value of -1 denotes a default value.
labelstringText Label.
poswx.PointWindow position.
sizewx.WindowWindow size.
stylelongWindow style.
namestringWindow name.

Example #1:




# import wxPython
import wx
  
# create base class
class TextExample(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(TextExample, self).__init__(*args, **kwargs)
  
        # lets put some text
        st = wx.StaticText(self, label ="Welcome to GeeksforGeeks")
  
def main():
    app = wx.PySimpleApp()
    frame = TextExample(None, title = "Read Text")
    frame.Show()
    app.MainLoop()
  
if __name__ == '__main__':
    main()

Output :



Example #2:




# import wxPython
import wx
  
  
class TextExample(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(TextExample, self).__init__(*args, **kwargs)
        # put some text
        st = wx.StaticText(self, label ="Welcome to GeeksforGeeks")
  
        # create font object
        font = st.GetFont()
  
        # increase text size
        font.PointSize += 10
  
        # make text bold
        font = font.Bold()
  
        # associate font with text
        st.SetFont(font)
          
def main():
    app = wx.PySimpleApp()
  
    frame = TextExample(None, title = "Read Text")
    frame.Show()
    app.MainLoop()
  
if __name__ == '__main__':
    main()

Output :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :