~cpp
import tkSimpleDialog
from Tkinter import *
from socket import *
class Main:
def __init__(self, aMaster, aUser, aSock):
self.frame = Frame(aMaster)
#for show texts
self.showscrollbar = Scrollbar(aMaster)
self.showscrollbar.place(x = 550, y = 0, width = 50, height = 550)
self.show = Listbox(aMaster, yscrollcommand = self.showscrollbar.set)
self.show.place(x = 0, y = 0, width = 585, height = 550)
self.showscrollbar.config(command = self.show.yview)
#for user list
self.listscrollbar = Scrollbar(aMaster)
self.listscrollbar.place(x = 800-50, y = 0, width = 50, height = 600)
self.list = Listbox(aMaster, yscrollcommand = self.listscrollbar.set)
self.list.place(x = 600, y = 0, width = 185, height = 600)
self.listscrollbar.config(command = self.list.yview)
#for input a string
self.edit = Entry(aMaster)
self.edit.place(x = 0, y = 550 , width = 600 , height = 50)
def sendMessage(self, event):
aUser.message = self.edit.get()
self.edit.delete(0, END)
csock.send(aUser)
self.recieveMassage()
def recieveMassage(self):
user = aSock.recv(1024)
self.show(user)
def show(self, aUser):
self.show.insert(END, "< " + str(aUser.ID) + " > : " + str(aUser.message))
class User:
def __init__(self, aID):
self.ID = aID
self.message = ''
self.isinEntry = True
if __name__ == "__main__":
root = Tk()
root.configure( width = 800, height = 600)
login = tkSimpleDialog
## login.Place.place_configure( root, x = 100, y = 100) #position
csock = socket(AF_INET, SOCK_STREAM)
try:
csock.connect(('165.194.17.59', 13))#make socket, connect
except:
print 'connect refuse'
csock.recv(1024)
ID = ''
while not ID:
ID = login.askstring(title = "Login", prompt="Enter ID", parent = root)
user = User(ID)
## csock.send(user)
## user = csock.recv(1024)
else:
win = Main(root, user, csock)
root.bind("<Return>", win.sendMessage)
while True:
user = csock.recv(1024)
root.mainloop()