import tkinter as tk
import tkinter.messagebox
import json
import random
import time
import os
# # 邮件发送相关模块###使用时请取消注释
# import smtplib
# from email.mime.text import MIMEText
# from email.utils import formataddr
"""为了存储数据将在与源文件相同路径下新建两个json文件,请不要随意删除"""
"""
普通管理员:可以完成对银行卡的各种操作
用户名:admin
密码:6818
超级管理员:可以查看所有用户的部分信息
用户名:superadmin
密码:000000
"""
"""有关Bank,Person,Card,Admin类的定义"""
class Admin:
def __init__(self):
self.num = 'admin'
self.password = '6818'
self.superadmin = 'superadmin'
self.superpassword = '000000'
class Card:
def __init__(self, cardid, password, money):
self.cardid = cardid
self.password = password
self.money = money
self.lock = False
class Person:
def __init__(self, name, age, phone, person_id,e_mail, card):
self.name = name # 姓名
self.person_id = person_id # 身份证号
self.age = age # 出生年份
self.phone = phone # 电话
self.e_mail = e_mail # 邮箱
self.card = card # Card类的实例化对象
class Bank:
def __init__(self, user_all, user_error):
self.user_all = user_all
self.user_error = user_error
def superlogin(self):
super_win = tk.Tk()
super_win.title('超级管理后台')
super_win.geometry('600x480')
all_list = []
lab_ti = tk.Label(super_win,text='银行系统信息统计', font=('宋体', 28))
lab_ti.place(x=160,y=60)
lab_ti = tk.Label(super_win, text='本系统共注册{}位用户'.format(self.user_all['count']), font=('宋体', 16))
lab_ti.place(x=170, y=128)
lab_titl = tk.Label(super_win, text="银行卡号"+' '*6+"户主姓名"+' '*6+"身份证号", font=('宋体', 12))
lab_titl.place(x=150, y=210)
for dic in self.user_all['users']:
st = (dic['card']['cardid']+' '*12+dic['person']['name'])
if len(st) <= 50:
y = 50 - len(st)
st += ' '*y
st += dic['person']['person_id']
all_list.append(st)
sc = tkinter.Scrollbar(super_win)
sc.pack(side=tkinter.RIGHT, fill=tkinter.Y)
lb = tk.Listbox(super_win, width=50, yscrollcommand=sc.set)
sc.config(command=lb.yview)
#
lb.place(x=140, y=240)
for item in all_list:
lb.insert(tk.END, item)
super_win.mainloop()
def getid(self,n=6):
"""生成随机卡号"""
s = ''
for i in range(n):
ch = chr(random.randrange(ord('0'), ord('9')+1))
s += ch
return s
def bankmain(self):
"""银行系统执行逻辑主程序"""
# 实例化一些对象
ad = Admin()
# 含有admin登录界面
win_admin_log = tk.Tk()
win_admin_log.title('银行系统管理员登录')
win_admin_log.geometry('680x460')
win_admin_log.resizable(0, 0)
# 标题
tit_lab = tk.Label(win_admin_log, text='银行管理系统', font=('华文彩云', 30))
tit_lab.place(x=250, y=80)
# 登录框
name_log = tk.Label(win_admin_log, text='管理员用户名', font=('宋体', 14))
name_log.place(x=140, y=240)
pasword_log = tk.Label(win_admin_log, text='管理员密码', font=('宋体', 14))
pasword_log.place(x=160, y=300)
# 登录entry
var_name = tk.StringVar()
var_name.set('') # 非测试时为空
en_name = tk.Entry(win_admin_log, textvariable=var_name, bd=4, font=('宋体', 14))
en_name.place(x=260, y=240)
var_pasw = tk.StringVar()
var_pasw.set('') # 非测试时为空
en_pasw = tk.Entry(win_admin_log, textvariable=var_pasw, bd=4, font=('宋体', 14), show='*')
en_pasw.place(x=260, y=300)
tk.Label(win_admin_log, text='当前时间:', font=('宋体', 12)).place(x=10, y=420)
clock = tk.Label(win_admin_log, text='', font=('ds-digital', 12))
clock.place(x=86, y=420)
def get_time():
"""获取时间"""
time2 = time.strftime('%Y-%m-%d %H:%M:%S')
clock.configure(text=time2)
clock.after(1000, get_time)
def check_admin():
"""检验身份"""
ad_name = var_name.get()
ad_pasw = var_pasw.get()
if ad_name == ad.num and ad_pasw == ad.password:
st = '登录成功!欢迎您,管理员!'
self.show_get('系统登录', st)
#win_admin_log.destroy()
# win_admin_log.withdraw()
self.menu_main()
else:
st = '密码错误或用户名错误!'
self.show_error('系统登录', st)
def check_superlogin():
ad_name = var_name.get()
ad_pasw = var_pasw.get()
if ad_name == ad.superadmin and ad_pasw == ad.superpassword:
st = '登录成功!欢迎您,超级管理员!'
self.show_get('系统登录', st)
# win_admin_log.destroy()
self.superlogin()
else:
st = '密码错误或用户名错误!'
self.show_error('系统登录', st)
# 程序说明界面驱动按钮
expl_a = tk.Button(win_admin_log, text='使用说明', font=('宋体', 10), command=self.explain)
expl_a.place(x=580, y=390)
# 登录按钮
login_a = tk.Button(win_admin_log, text='普通管理员登录', font=('宋体', 14), command=check_admin)
login_a.place(x=180, y=360)
# 按回车键可以进行普通管理员登录
def fucgo(event):
check_admin()
win_admin_log.bind('<Return>', fucgo)
# 超级管理员登录
login_super = tk.Button(win_admin_log, text='超级管理员登录', font=('宋体', 14), command=check_superlogin)
login_super.place(x=360, y=360)
# 获取时间
get_time()
# 系统用户数量
ls = tk.Label(win_admin_log, text='v2.0系统信息:本系统已注册{}位用户。'.format(user_all['count']), font=('宋体', 12))
ls.place(x=380, y=422)
# main loop
win_admin_log.mainloop()
def menu_main(self):
"""操作菜单及可视化页面"""
menu_win = tk.Tk()
menu_win.title('银行系统操作')
menu_win.geometry('600x500')
menu_win.resizable(0, 0)
# 标题
lab_maintitle = tk.Label(menu_win, text='功 能 菜 单', font=('华文琥珀',30))
lab_maintitle.place(x=200, y=70)
# 开户
n_getnew_card = tk.Button(menu_win, text='开 户', font=('宋体', 12), command=self.getnew_card, width=9, height=2)
n_getnew_card.place(x=70, y=160)
n_sech_card = tk.Button(menu_win, text='查 询', font=('宋体', 12), command=self.sech_card, width=9, height=2)
n_sech_card.place(x=270, y=160)
n_getmoney = tk.Button(menu_win, text='取 款', font=('宋体', 12), command=self.getmoney, width=9, height=2)
n_getmoney.place(x=470, y=160)
n_putmoney = tk.Button(menu_win, text='存 款', font=('宋体', 12), command=self.putmoney, width=9, height=2)
n_putmoney.place(x=70, y=260)
n_changemoney = tk.Button(menu_win, text='转 账', font=('宋体', 12), command=self.changemoney, width=9, height=2)
n_changemoney.place(x=270, y=260)
n_dellock = tk.Button(men