|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- # -*- coding: utf-8 -*-
- """
- @author: dlnb5
- """
- #运用easygui实现一个记账软件
- import easygui as g
- import os
- import os.path
- class Book:
- def __init__(self):
- pass
-
- def welcome(self):
- g.msgbox('欢迎使用本软件\n 本软件账本采用明文记录的方式\n 使用时请注意个人隐私 ','警告')
- def doccr(self):#此函数用于对文件进行读取操作
- if not os.path.exists('账本.txt'):
-
- self.f = open('账本.txt','w')
-
- self.f.write('感谢使用本系统\n')
- self.f.write('当前余额 0 元\n')
- self.f.close()
- self.f = open('账本.txt','r')
- else:
- self.f = open('账本.txt','r')
- self.b1 = self.f.readlines()
- self.rest1 = self.b1[-1] #读取当前文件的最后一行
- self.a1 = self.rest1.find(' ')
- self.a2 = self.rest1.find(' ',self.a1+1)
- self.rest = int(self.rest1[self.a1:self.a2])
- self.f.close()
-
- def iocome(self):#选择支出或者收入
- self.doccr()
- self.choice1 = g.buttonbox('你要记录收入还是支出呀','记账1.0 by dlnb',('收入','支出','查询账本','退出'))
- if self.choice1 == '收入':
- self.income()
- self.textshow()
- if self.choice1 == '支出':
- self.outcome()
- self.textshow()
- if self.choice1 == '查询账本':
- self.searchbo()
- if self.choice1 == '退出':
- pass
- def outcome(self):#记录支出
- try:
- self.input1 = g.multenterbox('请填写下面各项,带*为必填项','请输入您的支出',['您支出的项目是: ','您支出的花费是:'])
- self.outitem = self.input1[0]
- self.outpr = int(self.input1[1])
- g.msgbox('您支出在%s的花费是 %d元 已经记录成功\n'%(self.outitem,self.outpr))
- self.cal(-self.outpr)
- self.f = open('账本.txt','a')
- self.f.write('您支出在%s的花费是 %d元 已经记录成功\n'%(self.outitem,self.outpr))
- self.f.write('当前余额 %d 元\n'%self.rest)
- self.f.close()
- except:
- g.msgbox('您输入有误!下面为您显示账本')
-
-
-
- def income(self):#记录收入
- try:
- self.input2 = g.multenterbox('请填写下面各项,带*为必填项','请输入您的收入',['您收入的项目是: ','您收入的项目是:'])
- self.initem = self.input2[0]
- self.inpr = int(self.input2[1])
- g.msgbox('您%s的收入 %d元已经记录成功\n'%(self.initem,self.inpr))
- self.cal(self.inpr)
- self.f = open('账本.txt','a')
- self.f.write('您于%s的收入 %d元已经记录成功\n'%(self.initem,self.inpr))
- self.f.write('当前余额 %d 元\n'%self.rest)
- self.f.close()
- except:
- g.msgbox('您输入有误!下面为您显示账本')
-
- def cal(self,d):#此函数用于计算具体的花费数值
- self.rest = self.rest + d
- print('当前余额是 %d'%self.rest)
-
- def textshow(self):
- self.f = open('账本.txt','r')
- self.ts = g.textbox(msg='您的帐本如下',title = '您的帐本',text=self.f.readlines(),run=True)
- self.f.close()
- def searchbo(self):
- self.f = open('账本.txt','r')
- self.choice2 = g.buttonbox(self.f.read(),'记账1.0 by dlnb',('另存为...','关闭软件'))
- if self.choice2 == '另存为...':
- self.saveas()
- if self.choice2 == '关闭软件':
- self.choice1 = '退出'
- def saveas(self):
- self.f = open('账本.txt','r')
- self.filecon = self.f.read()
- self.another_path = g.filesavebox(default=".txt")
- if os.path.splitext(self.another_path)[1] != '.txt':
- self.another_path += '.txt'
- with open(self.another_path, "w") as self.new_file:
- self.new_file.write(self.filecon[:])
- book=Book()
- book.welcome()
- while True:
- book.iocome()
- if book.choice1 == '退出':
- break
-
复制代码
期待各位指导 |
|