总览
前言
本系统主要通过tkinter模块实现,通过读取对应的文件,实现登录注册
功能、信息的增删查改
功能。
主要实现
登录
def user_lo():
name = user_name_text.get()
pwd = user_pwd_text.get()
user_data = get_data()
if name != '' and pwd != '':
if name in user_data.keys():
if pwd == user_data[name]:
messagebox.showinfo(title='正确', message='登录成功,欢迎'+name+'的到来')
# print('登录成功,欢迎'+name+'的到来')
root.destroy()
else:
messagebox.showerror(title='错误', message='您输入的用户密码输入错误')
# print('您输入的用户密码输入错误')
else:
messagebox.showerror(title='错误', message='您输入的用户名不存在')
# print('您输入的用户名不存在')
else:
messagebox.showerror(title='错误', message='输入的账号和密码不能为空')
# print('输入的账号和密码不能为空'
注册
def pop_root():
top = Toplevel()
top.title('注册')
top.geometry('280x320+500+200') # 这里直接手动放置位置了
tk.Label(top, text='账号', font=('FangSong', 14), width=10).grid(row=1, column=0)
u_name = tk.StringVar()
u_name_entry = tk.Entry(top, textvariable=u_name, font=('FangSong', 14), width=15)
u_name_entry.grid(row=1, column=1)
tk.Label(top, text='密码', font=('FangSong', 14), width=10).grid(row=2, column=0)
u_pwd = tk.StringVar()
u_pwd_entry = tk.Entry(top, textvariable=u_pwd, font=('FangSong', 14), width=15)
u_pwd_entry.grid(row=2, column=1)
tk.Label(top, text='确认密码', font=('FangSong', 14), width=10).grid(row=3, column=0)
u_ppwd = tk.StringVar()
u_ppwd_entry = tk.Entry(top, textvariable=u_ppwd, font=('FangSong', 14), width=15)
u_ppwd_entry.grid(row=3, column=1)
def res_set():
name = u_name.get()
pwd = u_pwd.get()
ppwd = u_ppwd.get()
users = get_data()
if pwd == ppwd:
users[name] = pwd
with open('users.txt', 'w', encoding='utf-8') as f:
f.write(str(users))
f.flush()
f.close()
messagebox.showinfo(title='正确', message='注册成功') # messagebox 设置弹窗
top.destroy()
else:
messagebox.showerror('错误', message='两次密码输入不一致')
tk.Button(top, text='注册', font=('FangSong', 14), width=9, command=res_set).grid(row=4, columnspan=2, pady=20)
修改
def revise_person():
top = Toplevel()
top.title('修改个人信息')
top.geometry('280x320+500+200') # 这里直接手动放置位置了
tk.Label(top, text='修改人员的姓名', font=('FangSong', 12), width=15).grid(row=1, column=0)
u_name = tk.StringVar()
u_name_entry = tk.Entry(top, textvariable=u_name, font=('FangSong', 14), width=15)
u_name_entry.grid(row=1, column=1)
tk.Label(top, text='出生年月', font=('FangSong', 14), width=10).grid(row=2, column=0)
u_birth = tk.StringVar()
u_birth_entry = tk.Entry(top, textvariable=u_birth, font=('FangSong', 14), width=15)
u_birth_entry.grid(row=2, column=1)
tk.Label(top, text='性别', font=('FangSong', 14), width=10).grid(row=3, column=0)
u_sex = tk.StringVar()
u_sex_entry = tk.Entry(top, textvariable=u_sex, font=('FangSong', 14), width=15)
u_sex_entry.grid(row=3, column=1)
tk.Label(top, text='自我评价', font=('FangSong', 14), width=10).grid(row=4, column=0)
u_cont = tk.StringVar()
u_cont_entry = tk.Entry(top, textvariable=u_cont, font=('FangSong', 14), width=15)
u_cont_entry.grid(row=4, column=1)
def res_set():
name = u_name.get()
birth = u_birth.get()
sex = u_sex.get()
cont = u_cont.get()
persons = get_person_data()
if name not in persons.keys():
messagebox.showinfo(title='修改个人信息', message='人员不存在,直接新增') # messagebox 设置弹窗
else:
messagebox.showinfo(title='修改个人信息', message='修改成功') # messagebox 设置弹窗
persons[name] = (birth, sex, cont)
with open('persons.txt', 'w', encoding='utf-8') as f:
f.write(str(persons))
f.flush()
f.close()
top.destroy()
tk.Button(top, text='确认修改', font=('FangSong', 14), width=9, command=res_set).grid(row=5, columnspan=2, pady=20)
原文链接:https://blog.csdn.net/Dummy_/article/details/125604531
————————————————
版权声明:本文为博主转载文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。