下面是wxPython的一个伟大的教程(我选择的GUI API:非常强大,良好的社区/邮件列表,以及跨平台(它包装本机平台的部件))
http://wiki.wxpython.org/Getting%20Started
http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.10.1-py26.exe或
http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.10.1-py25.exe
:安装wxPython的,可以通过简单的setup.exe进行
(取决于python版本)
下面是一个简单的hello世界,一个简单的事件绑定到按钮。
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
text = wx.StaticText(self, label="hello, world!")
button = wx.Button(self, label="press me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(text, flag=wx.ALL, border=20)
sizer.Add(button, flag=wx.ALL, border=20)
self.SetSizer(sizer)
self.Layout()
self.Show(True)
self.Bind(wx.EVT_BUTTON, self.on_button, button)
def on_button(self, event):
wx.MessageBox("Hey!")
if __name__ == "__main__":
app = wx.App(False)
f = MyFrame()
,或者甚至更简单的例子:
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
frame.Show(True)
app.MainLoop()
app.MainLoop()