-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
38 lines (28 loc) · 1.14 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import tkinter as tk
import socket
def send_message():
message = input_entry.get() # Get the message from the input field
if message:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 2000))
client_socket.sendall(message.encode())
# sendAll
response = client_socket.recv(1024).decode() # Receive the "OK" response from the server
output_label.config(text=f"Server Response: {response}") # Display the server's response
client_socket.close()
def reset_client():
input_entry.delete(0, tk.END) # Clear the input field
output_label.config(text="Server Response: ") # Reset the output label
app = tk.Tk()
app.title("Tkinter Client")
input_label = tk.Label(app, text="Enter message:")
input_label.pack()
input_entry = tk.Entry(app)
input_entry.pack()
send_button = tk.Button(app, text="Send", command=send_message)
send_button.pack()
reset_button = tk.Button(app, text="Reset", command=reset_client) # Add Reset button
reset_button.pack()
output_label = tk.Label(app, text="Server Response: ")
output_label.pack()
app.mainloop()