鱼C论坛

 找回密码
 立即注册
查看: 1904|回复: 0

[作品展示] 期中作品--基于easygui实现的记账软件

[复制链接]
发表于 2020-1-30 09:32:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. # -*- coding: utf-8 -*-
  2. """

  3. @author: dlnb5

  4. """
  5. #运用easygui实现一个记账软件


  6. import easygui as g
  7. import os
  8. import os.path
  9. class Book:
  10.     def __init__(self):
  11.         pass
  12.    
  13.     def welcome(self):
  14.         g.msgbox('欢迎使用本软件\n 本软件账本采用明文记录的方式\n 使用时请注意个人隐私 ','警告')
  15.     def doccr(self):#此函数用于对文件进行读取操作
  16.         if not os.path.exists('账本.txt'):
  17.             
  18.             self.f = open('账本.txt','w')
  19.    
  20.             self.f.write('感谢使用本系统\n')
  21.             self.f.write('当前余额 0 元\n')
  22.             self.f.close()
  23.             self.f = open('账本.txt','r')
  24.         else:
  25.             self.f = open('账本.txt','r')
  26.         self.b1 = self.f.readlines()
  27.         self.rest1 = self.b1[-1] #读取当前文件的最后一行
  28.         self.a1 = self.rest1.find(' ')
  29.         self.a2 = self.rest1.find(' ',self.a1+1)
  30.         self.rest = int(self.rest1[self.a1:self.a2])
  31.         self.f.close()
  32.         
  33.     def iocome(self):#选择支出或者收入
  34.         self.doccr()
  35.         self.choice1 = g.buttonbox('你要记录收入还是支出呀','记账1.0 by dlnb',('收入','支出','查询账本','退出'))
  36.         if self.choice1 == '收入':
  37.             self.income()
  38.             self.textshow()
  39.         if self.choice1 == '支出':
  40.             self.outcome()
  41.             self.textshow()
  42.         if self.choice1 == '查询账本':
  43.             self.searchbo()
  44.         if self.choice1 == '退出':
  45.             pass
  46.     def outcome(self):#记录支出
  47.         try:
  48.             self.input1 = g.multenterbox('请填写下面各项,带*为必填项','请输入您的支出',['您支出的项目是: ','您支出的花费是:'])
  49.             self.outitem = self.input1[0]
  50.             self.outpr = int(self.input1[1])
  51.             g.msgbox('您支出在%s的花费是 %d元 已经记录成功\n'%(self.outitem,self.outpr))
  52.             self.cal(-self.outpr)
  53.             self.f = open('账本.txt','a')
  54.             self.f.write('您支出在%s的花费是 %d元 已经记录成功\n'%(self.outitem,self.outpr))
  55.             self.f.write('当前余额 %d 元\n'%self.rest)
  56.             self.f.close()
  57.         except:
  58.             g.msgbox('您输入有误!下面为您显示账本')
  59.             
  60.         
  61.         
  62.     def income(self):#记录收入
  63.         try:
  64.             self.input2 = g.multenterbox('请填写下面各项,带*为必填项','请输入您的收入',['您收入的项目是: ','您收入的项目是:'])
  65.             self.initem = self.input2[0]
  66.             self.inpr = int(self.input2[1])
  67.             g.msgbox('您%s的收入 %d元已经记录成功\n'%(self.initem,self.inpr))
  68.             self.cal(self.inpr)
  69.             self.f = open('账本.txt','a')
  70.             self.f.write('您于%s的收入 %d元已经记录成功\n'%(self.initem,self.inpr))
  71.             self.f.write('当前余额 %d 元\n'%self.rest)
  72.             self.f.close()
  73.         except:
  74.             g.msgbox('您输入有误!下面为您显示账本')
  75.         
  76.     def cal(self,d):#此函数用于计算具体的花费数值
  77.         self.rest = self.rest + d
  78.         print('当前余额是 %d'%self.rest)
  79.         
  80.     def textshow(self):
  81.         self.f = open('账本.txt','r')
  82.         self.ts = g.textbox(msg='您的帐本如下',title = '您的帐本',text=self.f.readlines(),run=True)
  83.         self.f.close()
  84.     def searchbo(self):
  85.         self.f = open('账本.txt','r')
  86.         self.choice2 = g.buttonbox(self.f.read(),'记账1.0 by dlnb',('另存为...','关闭软件'))
  87.         if self.choice2 == '另存为...':
  88.             self.saveas()
  89.         if self.choice2 == '关闭软件':
  90.             self.choice1 = '退出'

  91.     def saveas(self):
  92.         self.f = open('账本.txt','r')
  93.         self.filecon = self.f.read()
  94.         self.another_path = g.filesavebox(default=".txt")
  95.         if os.path.splitext(self.another_path)[1] != '.txt':
  96.             self.another_path += '.txt'
  97.         with open(self.another_path, "w") as self.new_file:
  98.             self.new_file.write(self.filecon[:])

  99. book=Book()        
  100. book.welcome()        
  101. while True:
  102.     book.iocome()
  103.     if book.choice1 == '退出':
  104.         break
  105.    
复制代码


期待各位指导
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-18 17:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表