User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 397,975 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,958 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Oct 2nd, 2007
Views: 2,417
A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget.
python Syntax
  1. # experiments with wx.StaticText(), set a font for the text
  2. # tested with Python25 and wxPython28 vegaseat 02oct2007
  3.  
  4. import wx
  5.  
  6. class MyFrame(wx.Frame):
  7. def __init__(self, parent, id, title, data):
  8. wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, size=(500, 380))
  9. panel = wx.Panel(self, -1)
  10.  
  11. # font type: wx.DEFAULT, wx.DECORATIVE, wx.ROMAN, wx.SCRIPT, wx.SWISS, wx.MODERN
  12. # slant: wx.NORMAL, wx.SLANT or wx.ITALIC
  13. # weight: wx.NORMAL, wx.LIGHT or wx.BOLD
  14. #font1 = wx.Font(10, wx.SWISS, wx.ITALIC, wx.NORMAL)
  15. # use additional fonts this way ...
  16. font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Comic Sans MS')
  17.  
  18. text1 = wx.StaticText(panel, -1, data, pos=(20,15))
  19. text1.SetFont(font1)
  20. # center frame on screen
  21. self.Center()
  22. # show the frame
  23. self.Show(True)
  24.  
  25.  
  26. data = """\
  27. Al Gore: The Wild Years
  28. America's Most Popular Lawyers
  29. Career Opportunities for History Majors
  30. Different Ways to Spell "Bob"
  31. Dr. Kevorkian's Collection of Motivational Speeches
  32. Ethiopian Tips on World Dominance
  33. Everything Men Know About Women
  34. Everything Women Know About Men
  35. One Hundred and One Spotted Owl Recipes by the EPA
  36. Staple Your Way to Success
  37. The Amish Phone Book
  38. The Engineer's Guide to Fashion
  39. Ralph Nader's list of pleasures"""
  40.  
  41. application = wx.PySimpleApp()
  42. # create instance of class MyFrame
  43. window = MyFrame(None, -1, "The World's Shortest Books", data)
  44. # start the event loop
  45. application.MainLoop()
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 12:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC