Skip to content

Commit 6fe0992

Browse files
committed
Global Chat GUI Ready
1 parent ec64778 commit 6fe0992

File tree

7 files changed

+90
-141
lines changed

7 files changed

+90
-141
lines changed

GlobalChatGUI.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from tkinter import *
2+
from KThread import *
3+
import pymongo
4+
myclient = pymongo.MongoClient(
5+
"mongodb+srv://CodingBlood:[email protected]/myFirstDatabase?retryWrites=true&w=majority")
6+
mydb = myclient["Chatbox"]
7+
mycol = mydb["UserDetails"]
8+
def main(username):
9+
def some():
10+
x = message.get()
11+
tasks(x)
12+
def tasks(x):
13+
def task1():
14+
mycol = mydb["GlobalChat"]
15+
for change in mycol.watch([{'$match': {'operationType': {'$in': ['insert']}}}]):
16+
t.insert(END, change["fullDocument"]["UName"] + " : " + change["fullDocument"]["Message"] + "\n")
17+
return 0
18+
def task2():
19+
GChat = mydb["GlobalChat"]
20+
mydict = {"UName": str(username), "Message": x}
21+
GChat.insert_one(mydict)
22+
return 0
23+
t1 = KThread(target=task1)
24+
t1.setDaemon(True)
25+
t1.start()
26+
task2()
27+
root1 = Toplevel()
28+
root1.geometry("1300x700")
29+
color = {"nero": "#252726", "orange": "#FF8700", "darkorange": "#FE6101"}
30+
root1.title("Chat Box")
31+
photo1 = PhotoImage(file=r"heytest.png")
32+
33+
hi=0
34+
35+
h = Scrollbar(root1, orient='horizontal')
36+
h.pack(side=BOTTOM, fill=X)
37+
v = Scrollbar(root1)
38+
v.pack(side=RIGHT, fill=Y)
39+
t = Text(root1, width=15, height=37, wrap=NONE,xscrollcommand=h.set,yscrollcommand=v.set)
40+
t.bind("<Key>", lambda e: "break")
41+
mydb = myclient["Chatbox"]
42+
GChat = mydb["GlobalChat"]
43+
for iterate in GChat.find({}, {"_id": 0, "UName": 1, "Message": 1}):
44+
t.insert(END, iterate["UName"].capitalize() + " : " + iterate["Message"] + "\n")
45+
t.pack(side=TOP, fill=X)
46+
h.config(command=t.xview)
47+
v.config(command=t.yview)
48+
49+
50+
canvas1 = Canvas(root1, width=400, height=400)
51+
canvas1.pack(fill="both", expand=True)
52+
canvas1.create_image(0, 0, image=photo1, anchor="nw")
53+
message = StringVar()
54+
b1 = Button(root1, text='SEND IT NOW --->>>',command=some, bg=color["nero"], fg=color["orange"], font=('Malgun Gothic Semilight', 10), width=15, height=3)
55+
l1 = Entry(root1, font=('Malgun Gothic Semilight', 25), bd=5, textvariable=message)
56+
canvas1.create_window(1110, 5, anchor="nw", window=b1)
57+
canvas1.create_window(5, 5, anchor="nw", window=l1, width=1100,height=60)
58+
root1.mainloop()
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
# def main(username):
70+
# print(
71+
# '''
72+
# =============================================================================================================================
73+
# | GGGGGGGGGGGGG CCCCCCCCCCCCCC |
74+
# | GGGGGGGGGGGGG CCCCCCCCCCCCCC |
75+
# | GGG CCC |
76+
# | GGG CCC |
77+
# | GGG GGGGG LL OOOOOOO BBBBBB AAAAAAAA LL CCC HH HH AAAAAAA TTTTTTTT |
78+
# | GGG GGGGG LL O O B B A A LL CCC HH HH AA AA TT |
79+
# | GGG GG LL O O BBBBBB AAAAAAAA LL CCC HHHHHHHH AAAAAAA TT |
80+
# | GGGGGGGGGGGGG LL O O B B A A LL CCCCCCCCCCCCCC HH HH AA AA TT |
81+
# | GGGGGGGGGGGGG LLLLLLLL OOOOOOO BBBBBB A A LLLLLLLL CCCCCCCCCCCCCC HH HH AA AA TT |
82+
# =============================================================================================================================
83+
# ''')
84+
# x = ""
85+

LoginPageGUI.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def some():
1919
l3.destroy()
2020
l4.destroy()
2121
b1.destroy()
22+
def Gchat():
23+
import GlobalChatGUI
24+
GlobalChatGUI.main(str(name))
2225
sb1 = Button(root1, text=' Global Chat', bg=color["nero"], fg=color["orange"],
2326
font=('Malgun Gothic Semilight', 25, "bold"), width=500, height=100, bd=5, image=login,
24-
compound=LEFT,
25-
anchor="nw", command=some)
27+
compound=LEFT,anchor="nw", command=Gchat)
2628
# canvas1.create_text(100, 245, "Username", width=50, height=1, fg=color["orange"])
2729
sl1 = Button(root1, text=' Public Chat Groups', bg=color["nero"], fg=color["orange"],
2830
font=('Malgun Gothic Semilight', 25, "bold"), width=500, height=100, bd=5, image=login,
3.07 KB
Binary file not shown.
2.81 KB
Binary file not shown.
184 Bytes
Binary file not shown.
648 Bytes
Binary file not shown.

main_gui.py

Lines changed: 1 addition & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -5,146 +5,8 @@
55
# mydb = myclient["Chatbox"]
66
# mycol = mydb["UserDetails"]
77
# # =========================REMEMBER IMPORTANT FOR CHATS==================================================================
8-
# # import tkinter as tk
9-
# #
10-
# # root = tk.Tk()
11-
# # root.geometry('600x400+80+40')
12-
# #
13-
# #
14-
# # class App:
15-
# # def __init__(self, root):
16-
# # self.entry_var = tk.StringVar()
17-
# # self.entry = tk.Entry(root, textvariable=self.entry_var)
18-
# # self.entry.bind('<Return>', self.show_output)
19-
# # self.entry.pack()
20-
# #
21-
# # def show_output(self, event):
22-
# # print(self.entry_var.get())
23-
# #
24-
# #
25-
# # App(root)
26-
# # tk.mainloop()\
27-
# # =======================================================================================================================
28-
# #=======================================================================================================================
29-
#
30-
# try:
31-
# from tkinter import *
32-
# except:
33-
# from tkinter import *
34-
#
35-
# class SampleApp(Tk):
36-
# def __init__(self):
37-
# Tk.__init__(self)
38-
# self.title("Chat Box")
39-
# self.geometry("1000x800")
40-
# self._frame = None
41-
# self.switch_frame(StartPage)
42-
#
43-
# def switch_frame(self, frame_class):
44-
# new_frame = frame_class(self)
45-
# if self._frame is not None:
46-
# self._frame.destroy()
47-
# self._frame = new_frame
48-
# self._frame.pack()
49-
#
50-
# class StartPage(Frame):
51-
# def __init__(self, master):
52-
# Frame.__init__(self, master)
53-
# Label(self, text="Hi there Welcome to Online Chatting Room", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
54-
# Label(self, text="Only benefit of this is no one knows you are here :):)", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
55-
# Label(self, text="Choose Wisely:---------------", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
56-
# Button(self, text='New User', fg='red', command=lambda: master.switch_frame(NUser), width=50, height=2).pack()
57-
# Button(self, text='Login', fg='red', command=lambda: master.switch_frame(ULogin), width=50, height=2).pack()
58-
# Button(self, text='Login Super User', fg='red', command=lambda: master.switch_frame(SULogin), width=50, height=2).pack()
59-
# Button(self, text='Delete account', fg='red', command=lambda: master.switch_frame(DUser), width=50, height=2).pack()
60-
# Button(self, text='New Super User', fg='red', command=lambda: master.switch_frame(NSUser), width=50, height=2).pack()
61-
# Button(self, text='Find Friend By Id', fg='red', command=lambda: master.switch_frame(FFinder), width=50, height=2).pack()
62-
# class FFinder(Frame):
63-
# def __init__(self, master):
64-
# Frame.__init__(self, master)
65-
# Frame.configure(self, bg='blue')
66-
# Label(self, text="Find My Friend", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
67-
# Button(self, text="Go back to start page",
68-
# command=lambda: master.switch_frame(StartPage)).pack()
69-
# class NSUser(Frame):
70-
# def __init__(self, master):
71-
# Frame.__init__(self, master)
72-
# Frame.configure(self, bg='blue')
73-
# Label(self, text="New Super User", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
74-
# Button(self, text="Go back to start page",
75-
# command=lambda: master.switch_frame(StartPage)).pack()
76-
# class DUser(Frame):
77-
# def __init__(self, master):
78-
# Frame.__init__(self, master)
79-
# Frame.configure(self, bg='blue')
80-
# Label(self, text="Delete User", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
81-
# Button(self, text="Go back to start page",
82-
# command=lambda: master.switch_frame(StartPage)).pack()
83-
# class SULogin(Frame):
84-
# def __init__(self, master):
85-
# Frame.__init__(self, master)
86-
# Frame.configure(self, bg='blue')
87-
# Label(self, text="Super User Login", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
88-
# Button(self, text="Go back to start page",
89-
# command=lambda: master.switch_frame(StartPage)).pack()
90-
#
91-
# class KahesiModeOnn(Frame):
92-
# def __init__(self, master):
93-
# Frame.__init__(self, master)
94-
# Frame.configure(self, bg='blue')
95-
# Label(self, text="Heya", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
96-
# Button(self, text="Go back to start page",
97-
# command=lambda: master.switch_frame(StartPage)).pack()
98-
# class ULogin(Frame):
99-
# def __init__(self, master):
100-
# Frame.__init__(self, master)
101-
# # Frame.configure(self, bg='red')
102-
# userid = StringVar()
103-
# paswrd = StringVar()
104-
# def some():
105-
# name = userid.get()
106-
# pass_wrd = paswrd.get()
107-
# myquery = {"UName": name}
108-
# mydoc = mycol.find(myquery)
109-
# for x in mydoc:
110-
# if x["UPassword"] == pass_wrd:
111-
# Button(self, text="Login Successful Click To Proceed", width=100, height=2, bd=5,
112-
# command=lambda: master.switch_frame(KahesiModeOnn)).pack()
113-
# else:
114-
# Button(self, text="Login Failed Retry...", width=100, height=2, bd=5,
115-
# command=lambda: master.switch_frame(ULogin)).pack()
116-
# userid.set("")
117-
# paswrd.set("")
118-
# Label(self, text="UserName", font=('Helvetica', 18, "bold")).pack()
119-
# Entry(self, bd=5, textvariable=userid).pack()
120-
# Label(self, text="Password", font=('Helvetica', 18, "bold")).pack()
121-
# Entry(self, bd=5, textvariable=paswrd).pack()
122-
# Button(self, text='Login', command=some, width=100, height=2, bd=5).pack()
123-
# Button(self, text="Go back to start page", width=100, height=2, bd=5,
124-
# command=lambda: master.switch_frame(StartPage)).pack()
125-
#
126-
# class NUser(Frame):
127-
# def __init__(self, master):
128-
# Frame.__init__(self, master)
129-
# Frame.configure(self, bg='red')
130-
# Label(self, text="New User", font=('Helvetica', 18, "bold")).pack(side="top", fill="x", pady=5)
131-
# Button(self, text="Go back to start page",
132-
# command=lambda: master.switch_frame(StartPage)).pack()
133-
# if __name__ == "__main__":
134-
# app = SampleApp()
135-
# app.mainloop()
136-
137-
138-
139-
140-
141-
142-
143-
144-
145-
146-
1478

9+
# # =======================================================================================================================
14810

14911
# setting switch function:
15012
def switch():

0 commit comments

Comments
 (0)