我很感興趣,在這個自己,kluged東西一起嘗試一下。我看着http://wiki.wxpython.org/UsingFonts并嘗試使用wx.TheFontList.FindOrCreateFont方法嘗試将字型加載到wxpython中。這失敗了,因為AddFontResourceA調用傳回0,這是一個failure code;它沒有提供進一步的資訊。感謝MICROSOFT!
如果将字型安裝到系統中(假設為Windows),則字型選擇将起作用。
我想這對wxPython的2.8,64位Windows 7,并與Proggy fonts
from ctypes import *
import os
gdi32= WinDLL("gdi32.dll")
font_path = os.path.abspath("ProggySquare.tff")
print font_path
print gdi32.AddFontResourceA(font_path)
import wx
class DrawPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event=None):
face = "ProggySquareTT"
prog_font = wx.TheFontList.FindOrCreateFont(28, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, face)
def_font = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL)
dc = wx.PaintDC(self)
dc.Clear()
dc.SetFont(prog_font)
dc.DrawText("Modern font Family", 50, 50)
app = wx.App(0)
frame = wx.Frame(None, title="Font Family")
DrawPanel(frame)
frame.Show()
#data = wx.FontData()
#data.EnableEffects(True)
#dlg = wx.FontDialog(None, data)
#if dlg.ShowModal() == wx.ID_OK:
# data = dlg.GetFontData()
# font = data.GetChosenFont()
#e = wx.FontEnumerator()
#e.EnumerateFacenames()
#elist= e.GetFacenames()
#elist.sort()
#print elist
app.MainLoop()