本文实例为大家分享了Python聊天室程序的具体代码,供大家参考,具体内容如下
客户端代码:
# Filename: socketClient.py
import socket
import sys
import threading
# Client GUI
from tkinter import *
import Pmw
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('localhost',10000)
print (sys.stderr,'connecting to %s port %s' % server_address)
sock.connect(server_address)
root = Tk()
# textDisplay
textDisplay = Pmw.ScrolledText(root)
textDisplay.pack(expand=1,padx=5,pady=5,side = LEFT)
# textInput
textInput = Pmw.ScrolledText(root)
textInput.pack(expand=1,side = LEFT)
# Send Button and its callback
def sendMs