wxpython select 聊天室server+client

一天看完python,一天wxpython,马上实践一下。


# -*- coding: utf-8 -*-
#Just for fuck jack!!!
#-----------------------------------
#author philsong    songbohr@163.com
#V0.0.1 2012-8-14   initial version
#V0.0.2 2012-8-15   use mulplex select, wait for notification that an input or output channel is ready
#-----------------------------------

import wx
import socket
import thread
import sys
import select
import Queue

class chatdlg(wx.Dialog):
    def __init__(self):
        wx.Dialog.__init__(self, None, -1, 'chat window', 
                size=(600, 500))

        self.DisplayText = wx.TextCtrl(self, -1, '', 
                size=(600, 350), style=wx.TE_MULTILINE)

        self.InputText = wx.TextCtrl(self, -1, "Hi, jack! What the fuck are u doing now?", 
                pos=(5, 370), size=(500, -1))

        self.sendButton = wx.Button(self, -1, "Send", pos=(510, 370))
        self.Bind(wx.EVT_BUTTON, self.OnSendClick, self.sendButton)
        self.sendButton.SetDefault()

        wx.StaticText(self, -1, "IP", (5, 415))
        self.IPText = wx.TextCtrl(self, -1, "219.147.23.114", 
                pos=(30, 415), size=(150, -1))
        wx.StaticText(self, -1, "Port", (200, 415))
        self.PortText = wx.TextCtrl(self, -1, "8001", 
                pos=(230, 415), size=(50, -1))

        self.cButton = wx.Button(self, -1, "Connect as a client", pos=(280, 415))
        self.Bind(wx.EVT_BUTTON, self.OnClientClick, self.cButton)
        self.sButton = wx.Button(self, -1, "Connect as a Server", pos=(390, 415))
        self.Bind(wx.EVT_BUTTON, self.OnSeverClick, self.sButton)

    def OnSendClick(self, event):
       #self.sendButton.SetLabel("Clicked")
        self.send_data = self.InputText.GetValue()
        try:
            self.client.send(self.send_data)
            self.DisplayText.AppendText('\nYour said:  [')
            self.DisplayText.AppendText(self.send_data)
            self.DisplayText.AppendText(']\n')
        except  socket.error, e:
            self.Disp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值