First version of client

Only "Login page" implemented
This commit is contained in:
Krzysztof Łaganowski 2020-12-07 06:25:32 +01:00
parent 518945c78d
commit 25f612007f

128
client/app.py Normal file
View File

@ -0,0 +1,128 @@
import tkinter as tk
import requests
FONT= ("Verdana", 12)
FONT_LARGE= ("Verdana", 20)
URL = "http://localhost:8000/api/authenticate"
TOKEN = ""
class SmartPicasso(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
self.title('SmartPicasso')
self.geometry('610x460')
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (LoginPage, MainView, RegisterView):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(LoginPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LoginPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10)
label1 = tk.Label(self, text='Login:', font=FONT)
label1.pack()
input1 = tk.Entry(self)
input1.pack()
label2 = tk.Label(self, text='Password:', font=FONT)
label2.pack()
input2 = tk.Entry(self)
input2.pack()
button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get()))
button.pack()
button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
button2.pack()
def login(self, controller, login, passw,):
print(login)
print(passw)
data = {
"email": str(login),
"password": str(passw)
}
resp = requests.post(URL, json=data)
print(resp)
if (resp.status_code==200):
response=resp.json()
TOKEN = response['token']
controller.show_frame(MainView)
else:
print("bad pass")
badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT)
badPassLabel.pack()
return()
class MainView(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10)
label_u = tk.Label(self, text="Main menu", font=FONT)
label_u.pack(pady=10,padx=10)
class RegisterView(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE)
label.pack(pady=10,padx=10)
label_u = tk.Label(self, text="Register", font=FONT)
label_u.pack(pady=10,padx=10)
label1 = tk.Label(self, text='Login:', font=FONT)
label1.pack()
input1 = tk.Entry(self)
input1.pack()
label2 = tk.Label(self, text='Password:', font=FONT)
label2.pack()
input2 = tk.Entry(self)
input2.pack()
label3 = tk.Label(self, text='Email:', font=FONT)
label3.pack()
input3 = tk.Entry(self)
input3.pack()
button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView))
button.pack()
app = SmartPicasso()
app.mainloop()