通过 wx.Font 对象,可以创建不同种类的字体,它有作如下的构建器:
特定的参数可以有以下选项:
“family”:
“weight”:
例子,fonts.py 程序展示了三种不同的字体.
#!/usr/bin/python
#coding=utf-8
#fonts.py
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(325, 320))
panel = wx.Panel(self, -1)
text1 = "Now listen to me mamanMama mamanYou're taking a way my last chancenDon't take it away"
text2 = '''You won't cry for my absence, I know -
You forgot me long ago.
Am I that unimportant...?
Am I so insignificant...?
Isn't something missing?
Isn't someone missing me?'''
text3 = '''But if I had one wish fulfilled tonight
I'd ask for the sun to never rise
If God passed a mic to me to speak
I'd say stay in bed, world
Sleepin peace'''
font1 = wx.Font(10, wx.NORMAL, wx.ITALIC, wx.NORMAL)
font2 = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)
font3 = wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL)
lyrics1 = wx.StaticText(panel, -1, text1, (30, 15), style=wx.ALIGN_CENTER)
lyrics1.SetFont(font1)
lyrics2 = wx.StaticText(panel, -1, text2, (30, 100), style=wx.ALIGN_CENTER)
lyrics2.SetFont(font2)
lyrics3 = wx.StaticText(panel, -1, text3, (30, 220), style=wx.ALIGN_CENTER)
lyrics3.SetFont(font3)
self.Center()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'fonts.py')
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
如图:
图:fonts.py