parent
3e9588e497
commit
24d1229598
@ -0,0 +1,55 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from MainPage import MainPage
|
||||
|
||||
|
||||
class LoginPage:
|
||||
def __init__(self, master):
|
||||
self.root = master
|
||||
self.root.title("请登录")
|
||||
# 设置窗口大小
|
||||
self.root.geometry("300x150+600+300")
|
||||
self.root.resizable(False, False)
|
||||
|
||||
# 创建并布局一个Frame
|
||||
self.page = tk.Frame(root)
|
||||
self.page.pack()
|
||||
|
||||
# 定义动态字符串变量
|
||||
self.username = tk.StringVar()
|
||||
self.password = tk.StringVar()
|
||||
|
||||
# 占位
|
||||
tk.Label(self.page).grid(row=0, column=0)
|
||||
|
||||
# tk.Label(page, text="^欢迎进入文章管理系统^", font=("Arial", 20, 'italic'), fg="red").grid(columnspan=2, row=0)
|
||||
|
||||
tk.Label(self.page, text="用户名:", font=('', 11)).grid(row=1, column=1, pady=10)
|
||||
tk.Entry(self.page, font=('', 11), textvariable=self.username).grid(row=1, column=2, pady=10)
|
||||
|
||||
tk.Label(self.page, text="密码:", font=('', 11)).grid(row=2, column=1, pady=10)
|
||||
tk.Entry(self.page, font=('', 11), textvariable=self.password, show='*').grid(row=2, column=2, pady=10)
|
||||
|
||||
tk.Button(self.page, text="登录", font=('', 11), command=self.login).grid(row=3, column=1)
|
||||
tk.Button(self.page, text="退出", font=('', 11), command=self.page.quit).grid(row=3, column=2)
|
||||
|
||||
def login(self):
|
||||
usn = self.username.get()
|
||||
pwd = self.password.get()
|
||||
if usn == "" or pwd == "":
|
||||
messagebox.showerror("错误", "请输入账号或密码")
|
||||
else:
|
||||
if usn == "admin" and pwd == "123456":
|
||||
messagebox.showinfo("提示", "登陆成功")
|
||||
# 关闭登录窗口
|
||||
self.page.destroy()
|
||||
# 载入主窗口
|
||||
MainPage(self.root)
|
||||
else:
|
||||
messagebox.showerror("错误", "账号或密码错误")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = tk.Tk()
|
||||
LoginPage(root)
|
||||
root.mainloop()
|
Loading…
Reference in new issue