Hello World
建立 Hello World 程式的簡單方法 :
import wx
app = wx.App(redirect=False)
frame = wx.Frame(parent=None, id=wx.ID_ANY, title='Hello World')
frame.Show()
app.MainLoop()
輸出:
一個更典型的例子是子類 wx.Frame :
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Hello World')
self.Show()
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = MyFrame()
app.MainLoop()
這也可以重寫為使用 Python 的超級 :
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
"""Constructor"""
super(MyFrame, self).__init__(*args, **kwargs)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None, title='Hello World')
app.MainLoop()