You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
4.5 KiB

import tkinter as tk
from tkinter import messagebox
from db import db
from MainPage import MainPage
from PIL import Image, ImageTk
class LoginPage:
def __init__(self, master):
self.root = master
self.root.geometry('1080x680')
self.root.title('dessert')
self.username = tk.StringVar()
self.password = tk.StringVar()
self.page = tk.Frame(self.root)
self.page.pack()
self.page1 = tk.Frame(self.root)
self.page1.pack()
self.canvas = tk.Canvas(self.page, width=1080, height=680)
self.canvas.pack()
# 加载背景图片
self.bg_image = Image.open('G:\\design\\pythonProject\\537.gif')
self.bg_photo = ImageTk.PhotoImage(self.bg_image)
self.canvas.create_image(0, 0, anchor=tk.NW, image=self.bg_photo)
tk.Label(self.page, text='账号', bg='#815c94', fg='white', font=('Arial', 12), width=5, height=1).place(relx=0.29, rely=0.4)
tk.Label(self.page, text='密码', bg='#815c94', fg='white', font=('Arial', 12), width=5, height=1).place(relx=0.29, rely=0.5)
tk.Entry(self.page, width=20, highlightthickness=1, highlightcolor='#815c94',relief='groove',textvariable=self.username).place(relx=0.4, rely=0.4)
tk.Entry(self.page, show='*', highlightthickness=1, highlightcolor='#815c94',relief='groove',textvariable=self.password).place(relx=0.4, rely=0.5)
tk.Button(self.page, text='登录', font=('宋体', 12), width=4, height=1, command=self.login,relief='solid', bd=0.5, bg='#815c94').place(relx=0.35, rely=0.63)
tk.Button(self.page, text='注册', font=('宋体', 12), width=4, height=1, bd=0.5, command=self.register_page,relief='solid', bg='#815c94').place(relx=0.48, rely=0.63)
tk.Button(self.page, text='退出', font=('宋体', 12), width=4, height=1, bd=0.5, command=self.page.quit,relief='solid', bg='#815c94').place(relx=0.61, rely=0.63)
def login(self):
name = self.username.get()
pwd = self.password.get()
flag, message = db.check_login(name, pwd)
if flag:
messagebox.showinfo("用户登录", "登录成功!即将进入菜单界面....")
self.page.destroy()
MainPage(self.root)
else:
messagebox.showwarning(title='警告', message='登录失败,请检查账号密码是否正确')
def register_page(self):
self.page1 = tk.Toplevel(self.root)
self.page1.title("用户注册中")
self.page1.geometry("400x300")
self.page1.resizable(False,False)
self.username1 = tk.StringVar()
self.pwd1 = tk.StringVar()
self.pwd2 = tk.StringVar()
tk.Entry(self.page1,width=20, highlightthickness=1, highlightcolor='#815c94',relief='groove',textvariable=self.username1).place(x=110,y=25)
tk.Entry(self.page1,show='*', highlightthickness=1, highlightcolor='#815c94', relief='groove',textvariable=self.pwd1).place(x=110,y=75)
tk.Entry(self.page1, show='*', highlightthickness=1, highlightcolor='#815c94', relief='groove',textvariable=self.pwd2).place(x=110,y=125)
tk.Label(self.page1, text='用户名', bg='#815c94', fg='white', font=('Arial', 12), width=5, height=1).place(x=60,y=25)
tk.Label(self.page1, text='密码', bg='#815c94', fg='white', font=('Arial', 12), width=5, height=1).place(x=60,y=75)
tk.Label(self.page1, text='确认密码', bg='#815c94', fg='white', font=('Arial', 12), width=5, height=1).place(x=60,y=125)
tk.Button(self.page1, text='注册', font=('宋体', 12), width=4, height=1, bd=0.5, command=self.register,relief='solid', bg='#815c94').place(relx=0.33, rely=0.63)
tk.Button(self.page1, text='返回', font=('宋体', 12), width=4, height=1, bd=0.5, command=self.back,relief='solid', bg='#815c94').place(relx=0.51, rely=0.63)
def register(self):
username = self.username.get()
pwd1 = self.pwd1.get()
pwd2 = self.pwd2.get()
if pwd1 == ' ' or pwd2 == ' ':
return messagebox.showerror("!不能不填密码!")
if pwd1 != pwd2:
messagebox.showerror("你两次密码不一样!")
else:
flag, message = db.check_register(username, pwd1)
if flag:
messagebox.showinfo("恭喜你,注册成功了")
def back(self):
self.page1.destroy()
if __name__ == '__main__':
root = tk.Tk()
LoginPage(root)
root.mainloop()