from socket import * from Tkinter import * #initalize send and recv sockets host = "127.0.0.1" portsend = 9999 portrecv = 9998 buf = 1024 sendaddr = (host, portsend) recvaddr = (host, portrecv) msgrecv = "" UDPSockRecv = socket(AF_INET, SOCK_DGRAM) UDPSockSend = socket(AF_INET, SOCK_DGRAM) #bind sock to portrecv UDPSockRecv.bind(recvaddr) class Application(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() self.create_widgets() def create_widgets(self): #instructions self.instructions = Label(self, text = "Enter Message to be sent here:") self.instructions.grid(row = 0, column = 0, sticky = W) #Entry Field self.msgsend = Text(self, width = 40, height = 5, wrap = WORD) self.msgsend.grid(row = 1, column = 0, sticky = N) #Enter Button(accepting string in entry field as argument for send() func) self.enterbttn = Button (self, text = " Send ", command = send(self.msgsend.get(0.0, END))) self.enterbttn.grid(row = 1, column = 2, sticky = W) #Exit Button self.exitbttn = Button(self, text = " Exit ", command = sys.exit) self.exitbttn.grid(row = 4, column = 2, sticky = N) #Message Receive Field self.msgrecv = Text(self, width = 40, height = 15, wrap = WORD) self.msgrecv.grid(row = 5, column = 0, sticky = S) def send(msgsend): UDPSockSend.sendto(msgsend,sendaddr) # main root = Tk() root.title("ChatterBox 1.0") root.geometry("354x325") app = Application(root) root.mainloop() #Receiving Loop #while 1: #msgrecv, recvaddr = UDPSockRecv.recvfrom(buf) #if msgrecv: #msgrecv["text"] = msgrecv #update text in textfield 'msgrecv' #else: #UDPSockRecv.close()