-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
79 lines (57 loc) · 1.7 KB
/
client.py
File metadata and controls
79 lines (57 loc) · 1.7 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import socket
import sys
import time
from tkinter import *
import tkinter as tk
def messagesent(mess,n):
messageVar = Message(root,text = mess, width=1000)
messageVar.config(bg='red')
messageVar.pack(fill=X)
def messagerecv(mess,n):
messageVar = Message(root,text = mess, width=1000)
messageVar.config(bg='yellow')
messageVar.pack(fill=X)
s= socket.socket()
def go_online():
print("Socket's on.")
port = 8080
s.connect(('10.2.98.150',port))
print("connected to chat server")
ourMessage ='You are now connected'
messageVar = Message(root,text = ourMessage, width=1000)
messageVar.config(bg='lightgreen')
messageVar.pack(fill=X)
def retrieve_input(line):
inputValue=textBox.get("1.0","end-1c")
messagesent(inputValue,line)
inputValue=inputValue.encode()
s.send(inputValue)
global n
n=n+1
print("kg: ",incoming_message)
def refreshnow(line):
incoming_message = s.recv(1024)
incoming_message = incoming_message.decode()
messagerecv(incoming_message,line)
global n
n=n+1
print("kg: ",incoming_message)
#window
root = tk.Tk()
root.geometry("300x700")
root.title("Chatroom")
frame = tk.Frame(root)
frame.pack()
#buttons
online=tk.Button(frame,text="GO ONLINE",fg="red",command=go_online)
online.pack(fill=X)
button = tk.Button(frame,text="QUIT",fg="red",command=quit)
button.pack(fill=X)
textBox=Text(frame, height=2,width=25,bg="grey")
textBox.pack(fill=X)
n=6
buttonCommit=tk.Button(frame,height=1,width=10,text="Send",command=lambda:retrieve_input(n))
buttonCommit.pack(fill=X)
refresh=tk.Button(frame,height=1,width=10,text="Refresh",command=lambda:refreshnow(n))
refresh.pack(fill=X)
root.mainloop()