Skip to content
Permalink
Browse files
Fixed username issue using .join method and added button to send message
  • Loading branch information
hortonr6 committed Nov 10, 2017
1 parent 0d44309 commit cb4e81c98e81a5fd241b4b23f1b24bce6f0fe645
Showing 1 changed file with 18 additions and 8 deletions.
@@ -5,20 +5,24 @@ import tkinter as tk
thisSocket = socket.socket()
thisSocket.connect(("127.0.0.1",5001))

def receiveMessage():
def receiveMessage(i):
''' Receives multiple messages from server if needed, until server
sends EndOfMessage and displays the recieved messages on the user
interface'''

global username
username = "User"

if i == 0:
global username
username = "User"

message = thisSocket.recv(1024).decode()
print(message)
while (message != "EndOfMessage"):
if username == "User" and "YOURNAMEWILLBE" in message:
nameholder = message.split()[1:]
username = nameholder[1:]
username = ''.join(nameholder)
username = username.title()
thisSocket.send("Received".encode())
message = thisSocket.recv(1024).decode()
continue
chatHistory.configure(state="normal")
thisSocket.send("Received".encode())
@@ -27,7 +31,7 @@ def receiveMessage():
chatHistory.configure(state="disabled") #prevents user from editing the chat history
message = thisSocket.recv(1024).decode()

def sendMessage(event):
def sendMessage(event=None):
'''Waits for the user to enter a messasge in the text entry box in the
interface and then takes this input from the user and feeds it to the
chatbot/server, allowing it to respond to the input appropriately.'''
@@ -42,7 +46,9 @@ def sendMessage(event):
chatHistory.see(tk.END)
chatHistory.configure(state="disabled")
userInput.delete(0, tk.END)
receiveMessage()
receiveMessage(i)

i = 0

#Creates the main window for the interface
window = tk.Tk()
@@ -64,7 +70,11 @@ userInput = tk.Entry(window)
userInput.pack(pady=15)
userInput.bind("<Return>", sendMessage)

receiveMessage() #Receives the initial message from the chatbot
sendBtn = tk.Button(window, command=sendMessage)
sendBtn.pack(side="left", pady=15)

receiveMessage(i) #Receives the initial message from the chatbot
i = i + 1

tk.mainloop() #Runs the GUI

0 comments on commit cb4e81c

Please sign in to comment.