Python设计与实现一款简单的手机银行系统。具体功能: (1)登录功能,使用学号和密码登录,密码连续输错三次则账号冻结; (2)具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失; (3)具有存款功能:可按不同货币存款,例如人民币、美元、欧元等; (4)具有取款功能:可快速取1000、2000、3000和其他金额等; (5)具有转账汇款功能:银行账号转账、手机号转账,转账记录,转账限额设置等; (6)具有投资理财功能,如基金投资、购买理财产品、购买个人养老金;
时间: 2024-04-05 19:29:14 浏览: 91
好的,我会给出一个简单的Python代码示例来实现这个手机银行系统。以下是代码:
```python
import sqlite3
from tkinter import *
# 创建数据库连接
conn = sqlite3.connect('bank.db')
cursor = conn.cursor()
# 创建用户信息表
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_info (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
name TEXT,
balance REAL,
last_month_income REAL,
last_month_expense REAL,
is_lost INTEGER
)
''')
conn.commit()
# 创建存款记录表
cursor.execute('''
CREATE TABLE IF NOT EXISTS deposit_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
currency TEXT NOT NULL,
amount REAL NOT NULL,
time TEXT NOT NULL
)
''')
conn.commit()
# 创建取款记录表
cursor.execute('''
CREATE TABLE IF NOT EXISTS withdraw_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
amount REAL NOT NULL,
time TEXT NOT NULL
)
''')
conn.commit()
# 创建转账记录表
cursor.execute('''
CREATE TABLE IF NOT EXISTS transfer_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
to_account TEXT NOT NULL,
amount REAL NOT NULL,
time TEXT NOT NULL
)
''')
conn.commit()
# 创建投资记录表
cursor.execute('''
CREATE TABLE IF NOT EXISTS investment_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id TEXT NOT NULL,
investment_type TEXT NOT NULL,
amount REAL NOT NULL,
time TEXT NOT NULL
)
''')
conn.commit()
# 登录界面
def login():
global user_id_entry, password_entry, login_window
# 验证学号和密码是否正确
cursor.execute('SELECT * FROM user_info WHERE student_id = ? AND password = ?', (user_id_entry.get(), password_entry.get()))
user_info = cursor.fetchone()
if user_info:
# 登录成功,跳转到主界面
login_window.destroy()
main_page(user_info)
else:
# 登录失败,弹出提示框
messagebox.showerror('错误', '学号或密码错误')
# 密码输入框清空
password_entry.delete(0, END)
# 密码输入框获取焦点
password_entry.focus()
# 更新密码错误次数
global password_errors
password_errors += 1
if password_errors >= 3:
# 密码错误次数达到3次,冻结账户
cursor.execute('UPDATE user_info SET is_lost = 1 WHERE student_id = ?', (user_id_entry.get(),))
conn.commit()
messagebox.showerror('错误', '密码错误次数达到3次,账户已冻结')
password_errors = 0
# 主界面
def main_page(user_info):
# 创建主界面
global main_window, balance_label, income_label, expense_label
main_window = Tk()
main_window.title('手机银行系统 - 主页')
# 显示用户信息
name_label = Label(main_window, text='姓名:' + user_info[3])
name_label.pack()
balance_label = Label(main_window, text='余额:' + str(user_info[4]))
balance_label.pack()
income_label = Label(main_window, text='近一个月收入:' + str(user_info[5]))
income_label.pack()
expense_label = Label(main_window, text='近一个月支出:' + str(user_info[6]))
expense_label.pack()
# 创建操作按钮
deposit_button = Button(main_window, text='存款', command=deposit_window)
deposit_button.pack(pady=10)
withdraw_button = Button(main_window, text='取款', command=withdraw_window)
withdraw_button.pack(pady=10)
transfer_button = Button(main_window, text='转账', command=transfer_window)
transfer_button.pack(pady=10)
investment_button = Button(main_window, text='投资理财', command=investment_window)
investment_button.pack(pady=10)
main_window.mainloop()
# 存款窗口
def deposit_window():
global deposit_currency_entry, deposit_amount_entry, deposit_window
deposit_window = Toplevel()
deposit_window.title('存款窗口')
# 货币选择
deposit_currency_label = Label(deposit_window, text='货币')
deposit_currency_label.grid(row=0, column=0)
deposit_currency_entry = Entry(deposit_window)
deposit_currency_entry.grid(row=0, column=1)
# 存款金额
deposit_amount_label = Label(deposit_window, text='存款金额')
deposit_amount_label.grid(row=1, column=0)
deposit_amount_entry = Entry(deposit_window)
deposit_amount_entry.grid(row=1, column=1)
# 存款按钮
deposit_button = Button(deposit_window, text='存款', command=deposit)
deposit_button.grid(row=2, column=0, columnspan=2, pady=10)
deposit_window.mainloop()
# 存款操作
def deposit():
# 检查货币和金额是否填写
if deposit_currency_entry.get() == '' or deposit_amount_entry.get() == '':
messagebox.showerror('错误', '请输入货币和金额')
return
# 更新余额
cursor.execute('UPDATE user_info SET balance = balance + ? WHERE student_id = ?', (float(deposit_amount_entry.get()), user_id_entry.get()))
conn.commit()
# 记录存款
cursor.execute('INSERT INTO deposit_record (student_id, currency, amount, time) VALUES (?, ?, ?, datetime("now", "localtime"))', (user_id_entry.get(), deposit_currency_entry.get(), float(deposit_amount_entry.get())))
conn.commit()
# 更新主界面显示
update_main_page()
# 关闭存款窗口
deposit_window.destroy()
# 取款窗口
def withdraw_window():
global withdraw_amount_entry, withdraw_window
withdraw_window = Toplevel()
withdraw_window.title('取款窗口')
# 取款金额
withdraw_amount_label = Label(withdraw_window, text='取款金额')
withdraw_amount_label.grid(row=0, column=0)
withdraw_amount_entry = Entry(withdraw_window)
withdraw_amount_entry.grid(row=0, column=1)
# 取款按钮
withdraw_button = Button(withdraw_window, text='取款', command=withdraw)
withdraw_button.grid(row=1, column=0, columnspan=2, pady=10)
withdraw_window.mainloop()
# 取款操作
def withdraw():
# 检查金额是否填写
if withdraw_amount_entry.get() == '':
messagebox.showerror('错误', '请输入金额')
return
# 检查余额是否充足
cursor.execute('SELECT * FROM user_info WHERE student_id = ?', (user_id_entry.get(),))
user_info = cursor.fetchone()
if float(withdraw_amount_entry.get()) > user_info[4]:
messagebox.showerror('错误', '余额不足')
return
# 更新余额
cursor.execute('UPDATE user_info SET balance = balance - ? WHERE student_id = ?', (float(withdraw_amount_entry.get()), user_id_entry.get()))
conn.commit()
# 记录取款
cursor.execute('INSERT INTO withdraw_record (student_id, amount, time) VALUES (?, ?, datetime("now", "localtime"))', (user_id_entry.get(), float(withdraw_amount_entry.get())))
conn.commit()
# 更新主界面显示
update_main_page()
# 关闭取款窗口
withdraw_window.destroy()
# 转账窗口
def transfer_window():
global to_account_entry, transfer_amount_entry, transfer_window
transfer_window = Toplevel()
transfer_window.title('转账窗口')
# 对方账户
to_account_label = Label(transfer_window, text='对方账户')
to_account_label.grid(row=0, column=0)
to_account_entry = Entry(transfer_window)
to_account_entry.grid(row=0, column=1)
# 转账金额
transfer_amount_label = Label(transfer_window, text='转账金额')
transfer_amount_label.grid(row=1, column=0)
transfer_amount_entry = Entry(transfer_window)
transfer_amount_entry.grid(row=1, column=1)
# 转账按钮
transfer_button = Button(transfer_window, text='转账', command=transfer)
transfer_button.grid(row=2, column=0, columnspan=2, pady=10)
transfer_window.mainloop()
# 转账操作
def transfer():
# 检查对方账户和金额是否填写
if to_account_entry.get() == '' or transfer_amount_entry.get() == '':
messagebox.showerror('错误', '请输入对方账户和金额')
return
# 检查余额是否充足
cursor.execute('SELECT * FROM user_info WHERE student_id = ?', (user_id_entry.get(),))
user_info = cursor.fetchone()
if float(transfer_amount_entry.get()) > user_info[4]:
messagebox.showerror('错误', '余额不足')
return
# 更新余额
cursor.execute('UPDATE user_info SET balance = balance - ? WHERE student_id = ?', (float(transfer_amount_entry.get()), user_id_entry.get()))
conn.commit()
# 记录转账
cursor.execute('INSERT INTO transfer_record (student_id, to_account, amount, time) VALUES (?, ?, ?, datetime("now", "localtime"))', (user_id_entry.get(), to_account_entry.get(), float(transfer_amount_entry.get())))
conn.commit()
# 更新主界面显示
update_main_page()
# 关闭转账窗口
transfer_window.destroy()
# 投资理财窗口
def investment_window():
global investment_type_entry
阅读全文