Welcome folks today in this blog post we will be looking at wxpython static text class example to display static text in bold with custom fonts and background color
. All the full source code of the application is given below.
Get Started
In order to get started you need to install the below library using the pip
command as shown below
pip install wxpython
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import wx class StaticTextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Static Text Example', size=(400, 300)) panel = wx.Panel(self, -1) wx.StaticText(panel, -1, "This is an example of static text", (100, 10)) rev = wx.StaticText(panel, -1, "Static Text With Reversed Colors", (100, 30)) rev.SetForegroundColour('white') rev.SetBackgroundColour('black') center = wx.StaticText(panel, -1, "align center", (100, 50), (160, -1), wx.ALIGN_CENTER) center.SetForegroundColour('white') center.SetBackgroundColour('black') right = wx.StaticText(panel, -1, "align right", (100, 70), (160, -1), wx.ALIGN_RIGHT) right.SetForegroundColour('white') right.SetBackgroundColour('black') str = "You can also change the font." text = wx.StaticText(panel, -1, str, (20, 100)) font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL) text.SetFont(font) wx.StaticText(panel, -1, "Your text\ncan be split\n" "over multiple lines\n\neven blank ones", (20,150)) wx.StaticText(panel, -1, "Multi-line text\ncan also\n" "be right aligned\n\neven with a blank", (220,150), style=wx.ALIGN_RIGHT) if __name__ == '__main__': app = wx.PySimpleApp() frame = StaticTextFrame() frame.Show() app.MainLoop() |
If you execute the above python script
by typing the below command
python app.py