-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
170 lines (130 loc) · 5 KB
/
main.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import tkinter as tk
from shared import problem
from zerok.client import ZKClient
# problem = GraphIsomorphism()
server_url = "http://127.0.0.1:5000"
client = ZKClient(problem=problem, server_url=server_url)
def hide_buttons():
register_btn.pack_forget()
login_btn.pack_forget()
def switch_to_register():
hide_buttons()
clear_previous_contents()
register_frame.place(relx=0.5, rely=0.5, anchor="center")
def switch_to_login():
hide_buttons()
clear_previous_contents()
login_frame.place(relx=0.5, rely=0.5, anchor="center")
def clear_previous_contents():
status_label_reg.config(text="")
username_entry_reg.delete(0, tk.END)
password_entry_reg.delete(0, tk.END)
status_label_login.config(text="")
username_entry_login.delete(0, tk.END)
password_entry_login.delete(0, tk.END)
def register():
global status_label_reg
username = username_entry_reg.get()
password = password_entry_reg.get()
if not username or not password:
status_label_reg.config(text="Please enter the details", fg="red")
return
hide_buttons()
register_btn_reg.config(state=tk.DISABLED)
back_btn_reg.config(state=tk.DISABLED)
ok, response = client.register_user(username, password)
if ok:
status_label_reg.config(text=response["message"], fg="green")
root.after(1000, switch_to_login)
# Disable the buttons again after successful registration
root.after(1000, enable_register_back_buttons)
else:
status_label_reg.config(text=response["message"], fg="red")
register_btn_reg.config(state=tk.NORMAL)
back_btn_reg.config(state=tk.NORMAL)
def enable_register_back_buttons():
register_btn_reg.config(state=tk.NORMAL)
back_btn_reg.config(state=tk.NORMAL)
def login():
global status_label_login
username = username_entry_login.get()
password = password_entry_login.get()
if not username or not password:
status_label_login.config(text="Please enter the details", fg="red")
return
hide_buttons()
login_btn_login.config(state=tk.DISABLED)
back_btn_login.config(state=tk.DISABLED)
ok, response = client.login_user(username, password)
if ok:
status_label_login.config(text=response["message"], fg="green")
root.after(1000, lambda: redirect_to_main_from_login(username))
else:
status_label_login.config(text=response["message"], fg="red")
login_btn_login.config(state=tk.NORMAL)
back_btn_login.config(state=tk.NORMAL)
def redirect_to_main_from_login(username):
back_to_main_from_login()
switch_to_main()
def show_buttons():
register_btn.config(state=tk.NORMAL)
login_btn.config(state=tk.NORMAL)
register_btn.place(relx=0.5, rely=0.5, anchor="center")
login_btn.place(relx=0.5, rely=0.6, anchor="center")
def back_to_main():
show_buttons()
login_frame.place_forget()
register_frame.place_forget()
clear_previous_contents()
register_btn_reg.config(state=tk.NORMAL)
back_btn_reg.config(state=tk.NORMAL)
# Function to handle back button press in the login page
def back_to_main_from_login():
hide_buttons()
login_frame.place_forget()
register_frame.place_forget()
show_buttons()
clear_previous_contents()
login_btn_login.config(state=tk.NORMAL)
back_btn_login.config(state=tk.NORMAL)
def switch_to_main():
hide_buttons()
clear_previous_contents()
show_buttons()
root = tk.Tk()
root.title("Client Interface") # Set title bar
# Main page buttons
register_btn = tk.Button(root, text="Register", command=switch_to_register)
login_btn = tk.Button(root, text="Login", command=switch_to_login)
show_buttons()
# Register Frame
register_frame = tk.Frame(root)
tk.Label(register_frame, text="Register", font=("Helvetica", 18)).pack(pady=10)
tk.Label(register_frame, text="Username:").pack()
username_entry_reg = tk.Entry(register_frame)
username_entry_reg.pack()
tk.Label(register_frame, text="Password:").pack()
password_entry_reg = tk.Entry(register_frame, show="*")
password_entry_reg.pack()
register_btn_reg = tk.Button(register_frame, text="Register", command=register)
register_btn_reg.pack(pady=10)
back_btn_reg = tk.Button(register_frame, text="Back", command=back_to_main)
back_btn_reg.pack(pady=10)
status_label_reg = tk.Label(register_frame, text="", fg="black")
status_label_reg.pack()
# Login Frame
login_frame = tk.Frame(root)
tk.Label(login_frame, text="Login", font=("Helvetica", 18)).pack(pady=10)
tk.Label(login_frame, text="Username:").pack()
username_entry_login = tk.Entry(login_frame)
username_entry_login.pack()
tk.Label(login_frame, text="Password:").pack()
password_entry_login = tk.Entry(login_frame, show="*")
password_entry_login.pack()
login_btn_login = tk.Button(login_frame, text="Login", command=login)
login_btn_login.pack(pady=10)
back_btn_login = tk.Button(login_frame, text="Back", command=back_to_main_from_login)
back_btn_login.pack(pady=10)
status_label_login = tk.Label(login_frame, text="", fg="black")
status_label_login.pack()
root.mainloop()