fork download
  1. #!/bin/python
  2. """
  3. Hello World, but with more meat.
  4. """
  5.  
  6. import wx
  7.  
  8. class HelloFrame(wx.Frame):
  9. """
  10. A Frame that says Hello World
  11. """
  12.  
  13. def __init__(self, *args, **kw):
  14. # ensure the parent's __init__ is called
  15. super(HelloFrame, self).__init__(*args, **kw)
  16.  
  17. # create a panel in the frame
  18. pnl = wx.Panel(self)
  19.  
  20. # and put some text with a larger bold font on it
  21. st = wx.StaticText(pnl, label="Hello World!", pos=(25,25))
  22. font = st.GetFont()
  23. font.PointSize += 10
  24. font = font.Bold()
  25. st.SetFont(font)
  26.  
  27. # create a menu bar
  28. self.makeMenuBar()
  29.  
  30. # and a status bar
  31. self.CreateStatusBar()
  32. self.SetStatusText("Welcome to wxPython!")
  33.  
  34.  
  35. def makeMenuBar(self):
  36. """
  37. A menu bar is composed of menus, which are composed of menu items.
  38. This method builds a set of menus and binds handlers to be called
  39. when the menu item is selected.
  40. """
  41.  
  42. # Make a file menu with Hello and Exit items
  43. fileMenu = wx.Menu()
  44. # The "\t..." syntax defines an accelerator key that also triggers
  45. # the same event
  46. helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",
  47. "Help string shown in status bar for this menu item")
  48. fileMenu.AppendSeparator()
  49. # When using a stock ID we don't need to specify the menu item's
  50. # label
  51. exitItem = fileMenu.Append(wx.ID_EXIT)
  52.  
  53. # Now a help menu for the about item
  54. helpMenu = wx.Menu()
  55. aboutItem = helpMenu.Append(wx.ID_ABOUT)
  56.  
  57. # Make the menu bar and add the two menus to it. The '&' defines
  58. # that the next letter is the "mnemonic" for the menu item. On the
  59. # platforms that support it those letters are underlined and can be
  60. # triggered from the keyboard.
  61. menuBar = wx.MenuBar()
  62. menuBar.Append(fileMenu, "&File")
  63. menuBar.Append(helpMenu, "&Help")
  64.  
  65. # Give the menu bar to the frame
  66. self.SetMenuBar(menuBar)
  67.  
  68. # Finally, associate a handler function with the EVT_MENU event for
  69. # each of the menu items. That means that when that menu item is
  70. # activated then the associated handler function will be called.
  71. self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
  72. self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
  73. self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
  74.  
  75.  
  76. def OnExit(self, event):
  77. """Close the frame, terminating the application."""
  78. self.Close(True)
  79.  
  80.  
  81. def OnHello(self, event):
  82. """Say hello to the user."""
  83. wx.MessageBox("Hello again from wxPython")
  84.  
  85.  
  86. def OnAbout(self, event):
  87. """Display an About Dialog"""
  88. wx.MessageBox("This is a wxPython Hello World sample",
  89. "About Hello World 2",
  90. wx.OK|wx.ICON_INFORMATION)
  91.  
  92.  
  93. if __name__ == '__main__':
  94. # When this module is run (not imported) then create the app, the
  95. # frame, show it, and start the event loop.
  96. app = wx.App()
  97. frm = HelloFrame(None, title='Hello World 2')
  98. frm.Show()
  99. app.MainLoop()
Runtime error #stdin #stdout #stderr 0.01s 7192KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 6, in <module>
ImportError: No module named wx