diff --git a/Client.py b/Client.py index ea6ed50..a514232 100644 --- a/Client.py +++ b/Client.py @@ -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("", 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