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.

92 lines
2.5 KiB

import subprocess
import tkinter as tk
import tkinter.messagebox as msgbox
import pickle
import threading
window = tk.Tk()
window.resizable(0, 0) #让窗口大小不变
window.title("停车场信息管理系统")
# 窗口居中
ww, wh = 400, 250
sw, sh = window.winfo_screenwidth(), window.winfo_screenheight()
x, y = (sw - ww) / 2, (sh - wh) / 2
window.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
# 欢迎使用
l_wlc = tk.Label(window, text="Welcome!", font=("Arial", 32))
l_wlc.pack() #将标签添加到窗口
# 用户名标签框
l_usr = tk.Label(window, text="用户名:")
l_usr.place(x=65, y=100)
l_key = tk.Label(window, text="密码:")
l_key.place(x=65, y=140)
# 用户名输入框
var1 = tk.StringVar()
var2 = tk.StringVar()
e_usr = tk.Entry(window, textvariable=var1)
e_key = tk.Entry(window, textvariable=var2, show="*")
e_usr.place(x=145, y=100)
e_key.place(x=145, y=140)
# 多线程实现同时打开新窗口和关闭本窗口
def tuichu():
window.quit()
def open_new():
subprocess.run(["python", "mainWindow.py"])
# 登录
def login():
t1 = threading.Thread(target=tuichu)
#t1.daemon = 1
t2 = threading.Thread(target=open_new)
#t2.daemon = 1
# 获得用户名字符串和密码字符串
usr = var1.get()
pwd = var2.get()
# 登录前检查:判断输入框是否为空
if usr != "":
if pwd != "":
# 将pickle内信息写入到listAll中
listAll = []
try:
with open("administrators.pickle", "rb+") as fp:
try:
while True:
temp = pickle.load(fp)
listAll.append(temp)
except EOFError:
pass
except FileNotFoundError:
with open("administrators.pickle", "wb") as fp:
pickle.dump(("admin", "admin"), fp)
else:
pass
# 检查该管理用户是否在存档中,密码是否匹配
for person in listAll:
if person[0] == usr and person[1] == pwd:
with open("record.txt", "w+") as file:
file.write("这是一个用于存储登录用户的名字的临时文件\n"+usr)
t1.start()
t2.start()
break
else:
msgbox.showerror(message="用户名或者密码错误!")
else:
msgbox.showerror("", "请输入密码")
else:
msgbox.showerror("", "请输入用户名")
btn_login = tk.Button(window, text="登录", width=8, command=login)
btn_login.place(x=145, y=190)
# 退出
btn_exit = tk.Button(window, text="退出", width=8, command=window.quit)
btn_exit.place(x=220, y=190)
window.mainloop()