服务端:
# _*_ coding:utf-8 _*_
# Filename:ServerUI.py
# Python在线聊天服务器端
import Tkinter
import tkFont
import socket
import thread
import time
import sys
class ServerUI():
title = 'Python在线聊天-服务器端V1.0'
local = '127.0.0.1'
port = 8808
#global serverSock;
serverSock = None
flag = False
#初始化类的相关属性,类似于Java的构造方法
def __init__(self):
self.root = Tkinter.Tk()
self.root.title(self.title)
#窗口面板,用4个frame面板布局
self.frame = [Tkinter.Frame(),Tkinter.Frame(),Tkinter.Frame(),Tkinter.Frame()]
#显示消息Text右边的滚动条
self.chatTextScrollBar = Tkinter.Scrollbar(self.frame[0])
self.chatTextScrollBar.pack(side=Tkinter.RIGHT,fill=Tkinter.Y)
#显示消息Text,并绑定上面的滚动条
ft = tkFont.Font(family='Fixdsys',size=11)
self.chatText = Tkinter.Listbox(self.frame[0],width=70,height=18,font=ft)
self.chatText['yscrollcommand'] = self.chatTextScrollBar.set
self.chatText.pack(expand=1,fill=Tkinter.BOTH)
self.chatTextScrollBar['command'] = self.chatText.yview()
self.frame[0].pack(expand=1,fill=Tkinter.BOTH)
#标签,分开消息显示Text和消息输入Text
label = Tkinter.Label(self.frame[1],height=2)
label.pack(fill=Tkinter.BOTH)
self.frame[1].pack(expand=1,fill=Tkinter.BOTH)
#输入消息Text的滚动条
self.inputTextScrollBar = Tkinter.Scrollbar(self.frame[2])
self.inputTextScrollBar.pack(side=Tkinter.RIGHT,fill=Tkinter.Y)
#输入消息Text,并与滚动条绑定
ft = tkFont.Font(family='Fixdsys',size=11)
self.inputText = Tkinter.Text(self.frame[2],width=70,height=8,font=ft)
self.inputText['yscrollcommand'] = self.inputTextScrollBar.set
self.inputText.pack(expand=1,fill=Tkinter.BOTH)
self.inputTex