1
+ from tkinter import *
2
+ import pymongo
3
+ import time
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 ():
9
+ def some ():
10
+ name = userid .get ()
11
+ pass_wrd = paswrd .get ()
12
+ myquery = {"UName" : name }
13
+ mydoc = mycol .find (myquery )
14
+ for x in mydoc :
15
+ if x ["UPassword" ] == pass_wrd :
16
+ print ("Login Successful" )
17
+ l1 .destroy ()
18
+ l2 .destroy ()
19
+ l3 .destroy ()
20
+ l4 .destroy ()
21
+ b1 .destroy ()
22
+ def Gchat ():
23
+ import GlobalChatGUI
24
+ GlobalChatGUI .main (str (name ))
25
+ def PuGrp ():
26
+ import GlobalChatGUI
27
+ GlobalChatGUI .main (str (name ))
28
+ def PrGrp ():
29
+ import GlobalChatGUI
30
+ GlobalChatGUI .main (str (name ))
31
+ def NPuGrp ():
32
+ import GlobalChatGUI
33
+ GlobalChatGUI .main (str (name ))
34
+ def NPriGrp ():
35
+ import GlobalChatGUI
36
+ GlobalChatGUI .main (str (name ))
37
+ sb1 = Button (root1 , text = ' Global Chat' , bg = color ["nero" ], fg = color ["orange" ],
38
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login ,
39
+ compound = LEFT ,anchor = "nw" , command = Gchat )
40
+ sl1 = Button (root1 , text = ' Public Chat Groups' , bg = color ["nero" ], fg = color ["orange" ],
41
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login ,
42
+ compound = LEFT ,
43
+ anchor = "nw" , command = PuGrp )
44
+ sl2 = Button (root1 , text = ' Private Chat Groups' , bg = color ["nero" ], fg = color ["orange" ],
45
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login ,
46
+ compound = LEFT ,
47
+ anchor = "nw" , command = PrGrp )
48
+ sl3 = Button (root1 , text = ' New Public Group' , bg = color ["nero" ], fg = color ["orange" ],
49
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login ,
50
+ compound = LEFT ,
51
+ anchor = "nw" , command = NPuGrp )
52
+ sl4 = Button (root1 , text = ' New Private Group' , bg = color ["nero" ], fg = color ["orange" ],
53
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login ,
54
+ compound = LEFT ,
55
+ anchor = "nw" , command = NPriGrp )
56
+ canvas1 .create_window (400 , 495 , anchor = "nw" , window = sb1 )
57
+ canvas1 .create_window (700 , 245 , anchor = "nw" , window = sl1 )
58
+ canvas1 .create_window (700 , 370 , anchor = "nw" , window = sl2 )
59
+ canvas1 .create_window (100 , 245 , anchor = "nw" , window = sl3 )
60
+ canvas1 .create_window (100 , 370 , anchor = "nw" , window = sl4 )
61
+ else :
62
+ print ("Login Failed" )
63
+ userid .set ("" )
64
+ paswrd .set ("" )
65
+ def switch ():
66
+ global btnState
67
+ if btnState is True :
68
+ # create animated Navbar closing:
69
+ for x in range (301 ):
70
+ navRoot .place (x = - x , y = 0 )
71
+ topFrame .update ()
72
+ # resetting widget colors:
73
+ brandLabel .config (bg = "gray17" , fg = "green" )
74
+ homeLabel .config (bg = color ["orange" ])
75
+ topFrame .config (bg = color ["orange" ])
76
+ # root.config(bg="gray17")
77
+
78
+ # turning button OFF:
79
+ btnState = False
80
+ else :
81
+ # make root dim:
82
+ brandLabel .config (bg = color ["nero" ], fg = "#5F5A33" )
83
+ # homeLabel.config(bg=color["nero"])
84
+ topFrame .config (bg = color ["nero" ])
85
+ root1 .config (bg = color ["nero" ])
86
+
87
+ # created animated Navbar opening:
88
+ for x in range (- 300 , 0 ):
89
+ navRoot .place (x = x , y = 0 )
90
+ topFrame .update ()
91
+
92
+ # turing button ON:
93
+ btnState = True
94
+ root1 = Toplevel ()
95
+ root1 .geometry ("1300x700" )
96
+ color = {"nero" : "#252726" , "orange" : "#FF8700" , "darkorange" : "#FE6101" }
97
+ root1 .title ("Chat Box" )
98
+ # setting switch state:
99
+ global btnState
100
+ btnState = False
101
+ # loading Navbar icon image:
102
+ navIcon = PhotoImage (file = "ham.png" )
103
+ closeIcon = PhotoImage (file = "goback.png" )
104
+ login = PhotoImage (file = r"login.png" , height = 100 , width = 100 )
105
+ signup = PhotoImage (file = r"signup.png" , height = 100 , width = 105 )
106
+ find = PhotoImage (file = r"find.png" , height = 100 , width = 105 )
107
+ delete = PhotoImage (file = r"delete.png" , height = 100 , width = 100 )
108
+ photo1 = PhotoImage (file = r"heytest.png" )
109
+ canvas1 = Canvas (root1 , width = 400 , height = 400 )
110
+ canvas1 .pack (fill = "both" , expand = True )
111
+ canvas1 .create_image (0 , 0 , image = photo1 , anchor = "nw" )
112
+
113
+ # top Navigation bar:
114
+ topFrame = Frame (root1 , bg = color ["orange" ])
115
+ canvas1 .create_window (0 , 0 , anchor = "nw" , window = topFrame , width = "1300" , height = "125" )
116
+ # topFrame.pack(side="top", fill=X)
117
+
118
+ # Header label text:
119
+ homeLabel = Label (topFrame , text = "Chat Box" , font = "Bahnschrift 95" , bg = color ["orange" ], fg = "gray17" , height = 2 ,
120
+ padx = 20 )
121
+ homeLabel .pack (side = "right" )
122
+
123
+
124
+
125
+
126
+
127
+ # Main label text:
128
+ userid = StringVar ()
129
+ paswrd = StringVar ()
130
+ brandLabel = Label (root1 , text = "" , font = "System 30" , bg = "gray17" , fg = "green" )
131
+ brandLabel .place (x = 100 , y = 250 )
132
+ b1 = Button (root1 , text = ' Login' , bg = color ["nero" ], fg = color ["orange" ],
133
+ font = ('Malgun Gothic Semilight' , 25 , "bold" ), width = 500 , height = 100 , bd = 5 , image = login , compound = LEFT ,
134
+ anchor = "nw" , command = some )
135
+ # canvas1.create_text(100, 245, "Username", width=50, height=1, fg=color["orange"])
136
+ l1 = Entry (root1 ,font = ('Malgun Gothic Semilight' , 25 , "bold" ),bd = 5 , textvariable = userid )
137
+ l2 = Entry (root1 ,font = ('Malgun Gothic Semilight' , 25 , "bold" ),bd = 5 , textvariable = paswrd , show = '*' )
138
+ l3 = Label (root1 , text = 'UserName' , width = 15 , height = 1 , font = ('Malgun Gothic Semilight' , 25 , "bold" ),bd = 5 )
139
+ l4 = Label (root1 , text = 'Password' , width = 15 , height = 1 , font = ('Malgun Gothic Semilight' , 25 , "bold" ),bd = 5 )
140
+ canvas1 .create_window (300 , 495 , anchor = "nw" , window = b1 )
141
+ canvas1 .create_window (700 , 245 , anchor = "nw" , window = l1 )
142
+ canvas1 .create_window (700 , 370 , anchor = "nw" , window = l2 )
143
+ canvas1 .create_window (100 , 245 , anchor = "nw" , window = l3 )
144
+ canvas1 .create_window (100 , 370 , anchor = "nw" , window = l4 )
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ # Navbar button:
156
+ navbarBtn = Button (topFrame , image = navIcon , bg = color ["orange" ], activebackground = color ["orange" ], bd = 0 , padx = 20 ,
157
+ command = switch )
158
+ navbarBtn .place (x = 10 , y = 10 )
159
+
160
+ # setting Navbar frame:
161
+ navRoot = Frame (root1 , bg = "gray17" , height = 1000 , width = 300 )
162
+ navRoot .place (x = - 300 , y = 0 )
163
+ Label (navRoot , font = "Bahnschrift 15" , bg = color ["orange" ], fg = "black" , height = 2 , width = 300 , padx = 20 ).place (x = 0 , y = 0 )
164
+
165
+ # set y-coordinate of Navbar widgets:
166
+ y = 180
167
+ # option in the navbar:
168
+ options = ["Login" , "Login Super User" , "New User" , "New Super User" , "Find Friend By Id" , "Delete account" ]
169
+ # Navbar Option Buttons:
170
+ for i in range (6 ):
171
+ Button (navRoot , text = options [i ], font = "BahnschriftLight 15" , bg = "gray17" , fg = color ["orange" ],
172
+ activebackground = "gray17" , activeforeground = "green" , bd = 0 ).place (x = 25 , y = y )
173
+ y += 40
174
+
175
+ # Navbar Close Button:
176
+ closeBtn = Button (navRoot , image = closeIcon , bg = color ["orange" ], activebackground = color ["orange" ], bd = 0 ,
177
+ command = switch )
178
+ closeBtn .place (x = 150 , y = 10 )
179
+
180
+ root1 .mainloop ()
0 commit comments