wxPython – Add text in window

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 :

Parameter Input Type Description
parent wx.Window Parent window. Should not be None.
id wx.WindowID Control identifier. A value of -1 denotes a default value.
label string Text Label.
pos wx.Point Window position.
size wx.Window Window size.
style long Window style.
name string Window name.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Output :

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Output :




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.