Sabtu, 13 Oktober 2007

"Cold Poetry" in a programming languages

Fonts



We create different kinds of fonts with the wx.Font object. It has the following constructor:




wx.Font(integer pointSize, wx.FontFamily family, integer style, integer weight,         bool underline = false, string faceName = '',         wx.FontEncoding encoding = wx.FONTENCODING_DEFAULT) 


The specified parameters can have the following options:


family:




  • wx.DEFAULT

  • wx.DECORATIVE

  • wx.ROMAN

  • wx.SWISS

  • wx.SCRIPT

  • wx.MODERN


style:




  • wx.NORMAL

  • wx.SLANT

  • wx.ITALIC


weight:




  • wx.NORMAL

  • wx.LIGHT

  • wx.BOLD


fonts.py script shows three different fonts.



document.write('Toggle line numbers');Toggle line numbers



   1 #!/usr/bin/python    2     3 # fonts.py    4     5 import wx    6     7 class MyFrame(wx.Frame):    8     def __init__(self, parent, id, title):    9         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(325, 320))   10    11         panel = wx.Panel(self, -1)   12    13         text1 = "Now listen to me mama\nMama mama\nYou're taking away my last chance\nDon't take it away"   14    15         text2 = '''You won't cry for my absence, I know -   16 You forgot me long ago.   17 Am I that unimportant...?   18 Am I so insignificant...?   19 Isn't something missing?   20 Isn't someone missing me?'''   21    22         text3 = '''But if I had one wish fulfilled tonight   23 I'd ask for the sun to never rise   24 If God passed a mic to me to speak   25 I'd say stay in bed, world   26 Sleep in peace'''   27    28         font1 = wx.Font(10, wx.NORMAL, wx.ITALIC, wx.NORMAL)   29         font2 = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)   30         font3 = wx.Font(10, wx.MODERN, wx.NORMAL, wx.BOLD)   31         lyrics1 = wx.StaticText(panel, -1, text1,(30,15), style=wx.ALIGN_CENTRE)   32         lyrics1.SetFont(font1)   33         lyrics2 = wx.StaticText(panel, -1, text2,(30,100), style=wx.ALIGN_CENTRE)   34         lyrics2.SetFont(font2)   35         lyrics3 = wx.StaticText(panel, -1, text3,(5,220), style=wx.ALIGN_CENTRE)   36         lyrics3.SetFont(font3)   37         self.Center()   38    39 class MyApp(wx.App):   40     def OnInit(self):   41         frame = MyFrame(None, -1, 'fonts.py')   42         frame.Show(True)   43         self.SetTopWindow(frame)   44         return True   45    46 app = MyApp(0)   47 app.MainLoop()

 fonts.png

SOURCE : AnotherTutorial (last edited 2007-07-09 22:59:01 by JoshEnglish)

http://wiki.wxpython.org/AnotherTutorial

0 komentar:

Posting Komentar