app = wxGUI() app.MainLoop()
9.2 Éè¼ÆÒ»¸ö´°Ì壬²¢·ÅÖÃÒ»¸ö°´Å¥£¬°´Å¥Ä¬ÈÏÎı¾Îª¡°¿ªÊ¼¡±£¬µ¥»÷°´Å¥ºóÎı¾±äΪ¡°½áÊø¡±£¬Ôٴε¥»÷ºó±äΪ¡°¿ªÊ¼¡±£¬Ñ»·Çл»¡£ import wx
class wxGUI(wx.App): def OnInit(self):
frame = wx.Frame(parent=None, title='wxGUI', size=(160,140)) panel = wx.Panel(frame, -1)
self.buttonOK = wx.Button(panel, -1, 'Start', pos=(0,0)) self.Bind(wx.EVT_BUTTON, self.OnButtonOK, self.buttonOK) frame.Show() return True
def OnButtonOK(self, event): if text == 'Start': elif text == 'End': app = wxGUI()
app.MainLoop()
9.3 Éè¼ÆÒ»¸ö´°Ì壬ģÄâQQµÇ¼½çÃ棬µ±Óû§ÊäÈëºÅÂë123456ºÍÃÜÂë654321ʱÌáʾÕýÈ·£¬·ñÔòÌáʾ´íÎó¡£ import wx
class wxGUI(wx.App): def OnInit(self):
frame pos=(350,350))
= wx.Frame(parent=None, title='Login', size=(250,150),
panel = wx.Panel(frame, -1)
label1 = wx.StaticText(panel, -1, 'UserName:', pos=(0,10),
style=wx.ALIGN_RIGHT)
label2 = wx.StaticText(panel, -1, 'Password:', pos=(0,30),
style=wx.ALIGN_RIGHT)
self.textName = wx.TextCtrl(panel, -1, pos=(70,10), size=(160,20))
self.textPwd = wx.TextCtrl(panel, -1, pos=(70,30),
size=(160,20),style=wx.TE_PASSWORD)
buttonOK = wx.Button(panel, -1, 'OK', pos=(30,60)) self.Bind(wx.EVT_BUTTON, self.OnButtonOK, buttonOK)
buttonCancel = wx.Button(panel, -1, 'Cancel', pos=(120,60)) self.Bind(wx.EVT_BUTTON, self.OnButtonCancel, buttonCancel) buttonOK.SetDefault() frame.Show() return True
def OnButtonOK(self, event):
if usrName=='123456' and usrPwd=='654321': wx.MessageBox('Right') else:
wx.MessageBox('Wrong') def OnButtonCancel(self, event): pass app = wxGUI() app.MainLoop()
µÚ10Õ ÍøÂç³ÌÐòÉè¼Æ
10.1 ¼òµ¥½âÊÍTCPºÍUDPÐÒéµÄÇø±ð¡£ ´ð£º
TCPÐÒéÊÇÃæÏòÁ¬½ÓµÄ¡¢¾ßÓÐÖÊÁ¿±£Ö¤µÄ¿É¿¿´«ÊäÐÒ飬µ«¿ªÏú½Ï´ó£»UDPÐÒéÊǾ¡×î´óÄÜÁ¦´«ÊäµÄÎÞÁ¬½ÓÐÒ飬¿ªÏúС£¬³£ÓÃÓÚÊÓƵÔÚÏߵ㲥£¨Video On Demand, VOD£©Ö®ÀàµÄÓ¦Óá£TCPÐÒéºÍUDPÐÒ鲢ûÓÐÓÅÁÓÖ®·Ö£¬½ö½öÊÇÊÊÓó¡ºÏÓÐËù²»Í¬¡£
10.2 ͬѧ֮¼äºÏ×÷±àдUDPͨÐųÌÐò£¬·Ö±ð±àд·¢ËͶ˺ͽÓÊն˴úÂ룬·¢ËͶ˷¢ËÍÒ»¸ö×Ö·û´®¡°Hello world!¡±¡£¼ÙÉè½ÓÊÕ¶ËÔÚ¼ÆËã»úµÄ5000¶Ë¿Ú½øÐнÓÊÕ£¬²¢ÏÔʾ½ÓÊÕÄÚÈÝ¡£
´ð£ºÊ×ÏÈʹÓÃipconfig/allÃüÁî²é¿´±¾»úIPµØÖ·£¬È»ºó·Ö±ð±àдÏÂÃæµÄ´úÂ룬²¢½«ÆäÖеÄIPµØÖ·Ì滻ΪÏàÓ¦µÄIPµØÖ·¡£
½ÓÊն˴úÂ룺 import socket
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((\¿Õ×Ö·û´®±íʾ±¾»úÈκοÉÓÃIPµØÖ· data, addr=s.recvfrom(1024) # »º³åÇø´óСΪ1024×Ö½Ú print ' received message:%s' % data #ÏÔʾ½ÓÊÕµ½µÄÄÚÈÝ s.close( )
·¢ËͶ˴úÂ룺