Python程序学习时,你需要注意一些问题,比如代码编程和调试过程中的问题,这些一定要仔细和认真,Python程序学习之前是要深入理解到底什么是Python,及他是怎么构成的。

虽然以上实现的功能很简单,但是我们确实建立了一个属于自己的服务器,一个按照自己定义的协议提供服务的server。开发的速度是不是很快呢?正如Twisted网站上说的Develop servers at lightning speed(闪电般的速度)。

只要将具体的协议做进一步的扩展,就能建立起功能强大的服务器了。在这里所提到的Twisted的功能仅仅是这座宝藏的冰山一角,在这里就不进一步去阐述了。有兴趣的朋友可以从Twisted的网站得到更多的信息。

但是别忘了,wxPython可是没有.NET平台的限制的哦。同时你从wxSimpleApp和wxFrame这样的类名是不是联想到了MFC的中Frame类、App类和Doc类呢?是的,wxPython也是通过相同的方式实现了MVC,使得整个GUI代码更加清晰,更加易于维护。如果你还不过瘾,嫌这个太简单,那就再来一个更加丰富的:

from wxPython.wx import *  



ID_ABOUT=101 




ID_EXIT=110 



class MainWindow(wxFrame):  


    def __init__(self,parent,id,title):  



        wxFrame.__init__(self,parent,wxID_ANY, title, size = (400,200), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)  




        self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)  



          



        filemenu= wxMenu()  



        filemenu.Append(ID_ABOUT, "&About"," Information about this program")  


        filemenu.AppendSeparator()  


        filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")  


 



        menuBar = wxMenuBar()  



        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar  


        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.  


        EVT_MENU(self, ID_ABOUT, self.OnAbout)   


        EVT_MENU(self, ID_EXIT, self.OnExit)    


        self.Show(true)  


 


    def OnAbout(self,e):  



        d= wxMessageDialog( self, " A sample editor  "  



                            " in wxPython","About Sample Editor", wxOK)  


                            


        d.ShowModal()   


        d.Destroy()   


 


    def OnExit(self,e):  


        self.Close(true)  # Close the frame.  


 



app = wxPySimpleApp()  




frame = MainWindow(None, -1, "Sample editor")  



app.MainLoop()