parent
e285d0b511
commit
cc87c76446
@ -0,0 +1,61 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
from db import db
|
||||||
|
from PIL import Image, ImageTk
|
||||||
|
from Mainpage import Mainage
|
||||||
|
from register import RegisterPage
|
||||||
|
|
||||||
|
class LoginPage:
|
||||||
|
|
||||||
|
def __init__(self, master):
|
||||||
|
self.root = master
|
||||||
|
self.root.geometry('300x180')
|
||||||
|
self.root.title('登录页')
|
||||||
|
self.username = tk.StringVar()
|
||||||
|
self.password = tk.StringVar()
|
||||||
|
self.page = tk.Frame(root)
|
||||||
|
self.page.pack()
|
||||||
|
|
||||||
|
# 加载背景图像
|
||||||
|
self.bg_image = Image.open("D:\桌面\图片\背景图.jpg") # 替换为你的背景图路径
|
||||||
|
self.bg_image = self.bg_image.resize((300, 180))
|
||||||
|
self.bg_imageTk = ImageTk.PhotoImage(self.bg_image)
|
||||||
|
|
||||||
|
# 创建背景图像的Label
|
||||||
|
bg_label = tk.Label(self.page, image=self.bg_imageTk)
|
||||||
|
bg_label.place(relwidth=1, relheight=1)
|
||||||
|
|
||||||
|
# 创建其他控件
|
||||||
|
tk.Label(self.page).grid(row=0, column=0)
|
||||||
|
|
||||||
|
tk.Label(self.page, text='账户:').grid(row=1, column=1, pady=10)
|
||||||
|
tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)
|
||||||
|
|
||||||
|
tk.Label(self.page, text='密码:').grid(row=2, column=1, pady=10)
|
||||||
|
tk.Entry(self.page, textvariable=self.password).grid(row=2, column=2)
|
||||||
|
|
||||||
|
tk.Button(self.page, text='注册:', command=self.registers).grid(row=3, column=1, pady=10)
|
||||||
|
tk.Button(self.page, text='登录:', command=self.login).grid(row=3, column=2, pady=10)
|
||||||
|
tk.Button(self.page, text='退出:', command=self.page.quit).grid(row=3, column=3, pady=10)
|
||||||
|
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
name = self.username.get()
|
||||||
|
pwd = self.password.get()
|
||||||
|
flag, message = db.check_login(name,pwd)
|
||||||
|
if flag:
|
||||||
|
self.page.destroy()
|
||||||
|
Mainage(self.root)
|
||||||
|
else:
|
||||||
|
messagebox.showwarning(title='警告', message=message)
|
||||||
|
|
||||||
|
def registers(self):
|
||||||
|
self.page.destroy()
|
||||||
|
RegisterPage(self.root)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
root = tk.Tk()
|
||||||
|
LoginPage(master=root)
|
||||||
|
root.mainloop()
|
Loading…
Reference in new issue