Using Fonts
Simple program that writes text to a panel.
Code Sample
1 import wx
2
3 class DrawPanel(wx.Panel):
4 def __init__(self, parent):
5 wx.Panel.__init__(self, parent)
6 self.Bind(wx.EVT_PAINT, self.OnPaint)
7
8 def OnPaint(self, event=None):
9 dc = wx.PaintDC(self)
10 dc.Clear()
11 dc.SetFont(wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL))
12 dc.DrawText("Modern font Family", 50, 50)
13
14 app = wx.App(0)
15 frame = wx.Frame(None, title="Font Family")
16 DrawPanel(frame)
17 frame.Show()
18 app.MainLoop()
Comments
You can use operating system fonts, if you are not concerned about platform independence or you can also access the system fonts by using wxfontDialog.
Custom Fonts on Windows
To load custom fonts on Windows use the following recipe:
This will load all .otf and .ttf fonts in the "fonts" subdirectory of your project.