| 
 
 1.V.001  
小马银行:使用文件夹保存当前信息,有记录  
# 账户类
class Account():
    def __init__(self, name, password, balance, operation):
        self.name = name
        self.password = password
        self.balance = balance
        self.operation = operation
        print(self.name, "账户" + self.operation + "成功")
    # 查询余额
    def check(self):
        print("当前余额:", self.balance)
    # 存钱
    def save(self, money):
        self.balance += money
        self.operation = "存入" + str(money)
    # 取钱
    def withdraw(self, money):
        if money <= self.balance:
            self.balance -= money
            self.operation = "取出" + str(money)
        else:
            print("没钱还想来得瑟")
    # 记录
    def record(self):
        f = open(self.name + ".txt", "a")
        text = self.name + "," + self.password + "," + str(self.balance) + "," + self.operation + "\n"
        f.write(text)
        f.close()
# 输入信息
name = input("请输入账户名称:")
password = input("请输入账户密码:")
try:
    file = open(name + ".txt","r")
# 账户不存在
except:
    balance = int(input("请输入账户余额:"))
    operation = "创建账户"
# 账户存在
else:
    # 读取txt文件中的记录
    lines = file.readlines()
    line = lines[len(lines)-1]
    linelist = line.split(",")
    balance = int(linelist[2])
    operation = "登陆账户"
# 创建账户
user = Account(name, password, balance, operation)
user.record()
while True:
    num = input("""
1、查询余额
2、存钱
3、取钱
""")
    if num == "1":
        user.check()
    elif num == "2":
        money = int(input("请输入想存的钱:"))
        user.save(money)
        user.record()
    elif num == "3":
        money = int(input("请输入想取的钱:"))
        user.withdraw(money)
        user.record()
    else:
        print("兄dei,输入123啊")  
2.V.100  
使用文件夹保存当前信息,无记录  
import tkinter
import tkinter.messagebox# 导入tkinter模块
class Account():
    def __init__(self, name, password, balance, operation):
        self.name = name
        self.password = password
        self.balance = balance
        self.operation = operation
    # 查询余额
    def check(self):
        print("当前余额:", self.balance)
    # 存钱
    def save(self, money):
        self.balance += money
        self.operation = "存入" + str(money)
    # 取钱
    def withdraw(self, money):
        if money <= self.balance:
            self.balance -= money
            self.operation = "取出" + str(money)
        else:
            print("没钱还想来得瑟")
    # 记录
    def record(self):
        f = open(self.name + ".txt", "a")
        text = self.name + "," + self.password + "," + str(self.balance) + "," + self.operation + "\n"
        f.write(text)
        f.close()
window = tkinter.Tk()  # 创建窗口
window.geometry("400x500")  # 设置窗口大小
window.title("注册/登录")  # 设置窗口标题
# 创建文字标签
label1 = tkinter.Label(window, text="小码银行", font=("微软雅黑", 20))
# 粘贴文字
label1.pack(pady=50)
label2 = tkinter.Label(window, text="账户名", font=("微软雅黑", 20))
label2.pack(pady=0)
# 创建“账户名”输入框
entry1 = tkinter.Entry(window, font=("微软雅黑", 20))
entry1.pack()
# “密码”文字标签
label3 = tkinter.Label(window, text="密码", font=("微软雅黑", 20))
label3.pack(pady=0)
# “密码”输入框
entry2 = tkinter.Entry(window, font=("微软雅黑", 20))
entry2.pack()
def log():
    print("恭喜你达成成就,电脑爆炸!")
    na=entry1.get()
    pw=entry2.get()
    try:
        f1=open(na+".txt","r")
    except:
        tkinter.messagebox.showerror("中毒","账户不存在")
    else:
        lin=f1.readlines()
        li=lines[len(lines)-1]
        lil=li.split(",")
        p1=lil[1]
        if pw==p1:
            b1=int(lil[2])
            us=Account(na,pw,b1,"登陆账户")
            us.record()
            tkinter.messagebox.showinfo("中毒","账号登录成功  ")
        else:
            tkinter.messagebox.showerror("中毒","密码错")
            
        
# “登录”按钮
btn1 = tkinter.Button(window, text="登录", font=("微软雅黑", 20), width=20,command=log)
btn1.pack(pady=20)
def sig():
    print("恭喜你达成成就,电脑中毒!")
    na=entry1.get()
    pw=entry2.get()
    try:
        open(na+".txt","r")
    except:
        
        us=Account(na,pw,0,"创建账户")
        us.record()
        tkinter.messagebox.showinfo("中毒","注册成功")
    else:
        tkinter.messagebox.showerror("中毒","账户存在")
# “注册”按钮
btn2 = tkinter.Button(window, text="注册", font=("微软雅黑", 20), width=20,command=sig)
btn2.pack()  
推选使用:  
1.  
python 原IDLE  
vscode? ? ? ? ? ? ? ? ?点击下载  
pycharm? ? ? ? ? ? ???点击下载  
2  
python 原IDLE 
                
        
        
    
 
 |