python日常记账本源代码,基于PySide6(Qt for Python 6)的账本,界面简洁、功能强大,支持保存文件、快速查询、绘制图表等,是平时记账的不错选择。账目查询、账本编辑、添加/删除、撤销/重做、统计数据、生成图表。
运行截图:




完整程序下载地址:python日常记账本源代码
main.py

import sys
from bisect import insort_right
from functools import partial
from os.path import basename
from webbrowser import open_new_tabfrom PySide6.QtWidgets import *
from PySide6.QtCore import Slot, QDate
from PySide6.QtGui import QStandardItem, QStandardItemModelfrom api import ApiError, openFile, query, saveFile
from dlgAdd import dlgAdd
from dlgCharts import dlgCharts
from dlgSettings import dlgSettings
from ui_dlgHelp import Ui_Dialog as Ui_dlgHelp
from ui_MainWindow import Ui_MainWindow# Version info
VERSION = '1.2.1'
CHANNEL = 'stable'
BUILD_DATE = '2022-08-25'
FULL_VERSION = f'{VERSION}-{CHANNEL} ({BUILD_DATE}) on {sys.platform}'app = QApplication(sys.argv)class AccountBookMainWindow(QMainWindow):version_str = '账本 ' + VERSIONunsaved_tip = '*'SUPPORTED_FILTERS = '账本文件(*.abf);;文本文件(*.txt);;所有文件(*.*)'def __init__(self, parent=None):# Initialize windowsuper().__init__(parent)self.ui = Ui_MainWindow()self.ui.setupUi(self)self.setWindowTitle('账本 ' + VERSION)self.labStatus = QLabel(self)self.ui.statusBar.addWidget(self.labStatus)# Initialize tableself.model = QStandardItemModel(0, 4, self)self.model.setHorizontalHeaderLabels(['日期', '事项', '金额', '备注'])self.ui.table.setModel(self.model)self.ui.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)self.__data = []self.on_actFile_New_triggered()self.ui.actEdit_Remove.setEnabled(False)# Connect slotsself.ui.table.selectionModel().selectionChanged.connect(self.__selectionChanged)self.model.itemChanged.connect(self.__itemChanged)def __updateTable(self, data):self.model.itemChanged.disconnect(self.__itemChanged)self.model.setRowCount(len(data))for row in range(len(data)):for col in range(len(data[row])):self.model.setItem(row, col, QStandardItem(data[row][col]))self.model.itemChanged.connect(self.__itemChanged)def __openFile(self, filename):try:self.__data = openFile(filename)except IOError:QMessageBox.critical(self, '错误', '文件打开失败。请稍后再试。')except ApiError:QMessageBox.critical(self, '错误', '文件格式错误。请检查文件完整性。')except Exception as e:QMessageBox.critical(self, '错误', '未知错误:' + str(e.with_traceback()))else:self.ui.searchEdit.clear()self.__key = ''self.__updateTable(self.__data)self.labStatus.setText(filename)self.setWindowTitle(self.version_str)self.__filename = filenamedef __saveFile(self, filename):try:saveFile(filename, self.__data)except IOError:QMessageBox.critical(self, '错误', '文件保存错误。请稍后再试。')except Exception as e:QMessageBox.critical(self, '错误', '未知错误:' + str(e.with_traceback()))else:self.labStatus.setText('保存成功:' + filename)self.setWindowTitle(self.version_str)self.__filename = filename@Slot()def on_actFile_New_triggered(self):self.__filename = self.__key = ''self.setWindowTitle(self.unsaved_tip + self.version_str)self.labStatus.setText('新文件')self.model.setRowCount(0)self.__data.clear()@Slot()def on_actFile_Open_triggered(self):filename, _ = QFileDialog.getOpenFileName(self, '打开', filter=self.SUPPORTED_FILTERS)if filename:self.__openFile(filename)@Slot()def on_actFile_Save_triggered(self):if self.__filename:self.__saveFile(self.__filename)else:filename, _ = QFileDialog.getSaveFileName(self, '保存', filter=self.SUPPORTED_FILTERS)if filename:self.__saveFile(filename)@Slot()def on_actFile_SaveAs_triggered(self):filename, _ = QFileDialog.getSaveFileName(self, '另存为', filter=self.SUPPORTED_FILTERS)if filename:self.__saveFile(filename)@Slot()def on_actFile_Settings_triggered(self):dlgSettings(self).exec()@Slot()def on_actHelp_About_triggered(self):dialog = QDialog(self)ui = Ui_dlgHelp()ui.setupUi(dialog)for link in (ui.githubLink, ui.giteeLink, ui.licenseLink, ui.readmeLink):link.clicked.connect(partial(open_new_tab, link.description()))ui.labVersion.setText('版本号:' + FULL_VERSION)ui.btnUpdate.clicked.connect(partial(open_new_tab, 'https://github.com/GoodCoder666/AccountBook/releases'))dialog.exec()@Slot()def on_actHelp_AboutQt_triggered(self):QMessageBox.aboutQt(self, '关于Qt')@Slot()def on_actEdit_Add_triggered(self):dialog = dlgAdd(self)if dialog.exec() == QDialog.Accepted:row = dialog.getRow()insort_right(self.__data, row)self.__updateTable(query(self.__data, self.__key))self.setWindowTitle(self.unsaved_tip + self.version_str)@Slot()def on_actEdit_Remove_triggered(self):rows = list(set(map(lambda idx: idx.row(), self.ui.table.selectedIndexes())))for row in rows:self.__data.remove([self.model.item(row, col).text() for col in range(self.model.columnCount())])self.model.itemChanged.disconnect(self.__itemChanged)self.model.removeRows(rows[0], len(rows))self.model.itemChanged.connect(self.__itemChanged)self.setWindowTitle(self.unsaved_tip + self.version_str)def __selectionChanged(self):self.ui.actEdit_Remove.setEnabled(self.ui.table.selectionModel().hasSelection())def __itemChanged(self, item: QStandardItem):i, j, new = item.row(), item.column(), item.text()if (old := self.__data[i][j]) == new: returnif j == 0 and not QDate.fromString(new, 'yyyy/MM/dd').isValid():QMessageBox.critical(self, '错误', '日期格式错误。')self.model.itemChanged.disconnect(self.__itemChanged)item.setText(old)self.model.itemChanged.connect(self.__itemChanged)returnrow = self.__data.pop(i)row[j] = newinsort_right(self.__data, row)self.__updateTable(query(self.__data, self.__key))self.setWindowTitle(self.unsaved_tip + self.version_str)@Slot()def on_searchEdit_textChanged(self):self.__key = self.ui.searchEdit.text()self.__updateTable(query(self.__data, self.__key))@Slot()def on_actStat_Show_triggered(self):if self.__data:dlgCharts(self.__data, self).exec()else:QMessageBox.information(self, '提示', '请添加数据以使用统计功能。')def closeEvent(self, event):if not self.windowTitle().startswith(self.unsaved_tip): returnfilename = basename(self.__filename) if self.__filename else '新文件'messageBox = QMessageBox(parent=self, icon=QMessageBox.Warning, windowTitle='提示',text=f'是否要保存对 {filename} 的更改?', informativeText='如果不保存,你的更改将丢失。',standardButtons=QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)messageBox.setButtonText(QMessageBox.Save, '保存')messageBox.setButtonText(QMessageBox.Discard, '不保存')messageBox.setButtonText(QMessageBox.Cancel, '取消')reply = messageBox.exec()if reply == QMessageBox.Save:self.on_actFile_Save_triggered()event.accept()elif reply == QMessageBox.Discard:event.accept()else:event.ignore()def dragEnterEvent(self, event):event.accept()def dropEvent(self, event):self.__openFile(event.mimeData().text()[8:]) # [8:] is to get rid of 'file:///'mainform = AccountBookMainWindow()
mainform.show()sys.exit(app.exec())

完整程序下载地址:python日常记账本源代码

python日常记账本源代码,基于PySide6,支持快速查询、绘制图表相关推荐

  1. Python小项目俄罗斯方块代码基于pygame编写

    python实习作业或者期末作业,俄罗斯方块,基于pygame编写 有很多小伙伴想要找一些小项目练练手,下面是我在闲暇时写的一个俄罗斯方块的一个小游戏,它是基于pygame板块来实现的 这是它的首页界 ...

  2. python血条游戏代码_零基础快速学十二课Python完整游戏代码,使用「格式符%」来处理...

    十二课Python不同数据类型的拼接方式,使用[格式符%]来处理 不过它还没有全部解决:打印出每局结果,三局两胜打印最终战果.这就是版本3.0需要做的事情. 打印战果,三局两胜. 对比2.0版本,在3 ...

  3. 用python画小猪佩奇代码_Python turtle模块实例:绘制小猪佩奇(上)

    在上一节教程中,我们已经对小猪佩奇进行了分析,现在我们就来进行绘制. 设置画布和画笔 首先,我们定义一个 setting() 函数,用它来设置画布和画笔.setting() 函数的代码如下所示. de ...

  4. python 字节流分段_如何在Python中编写简单代码,并且速度超越Spark?

    全文共 3482字,预计学习时长 7分钟 如今,大家都在Python工具(pandas和Scikit-learn)的简洁性.Spark和Hadoop的可扩展性以及Kubernetes的操作就绪之间做选 ...

  5. python 蓝牙开发_基于python实现蓝牙通信代码实例

    这篇文章主要介绍了基于python实现蓝牙通信代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 安装和示例 linux下安装 sudo apt ...

  6. Python网上商城源代码,基于Django+MySQL+Redis,支持支付宝付款

    Python网上商城源代码,基于Django+MySQL+Redis,支持支付宝付款,实现:用户登录注册,商品展示,商品详情界面,搜索商品,将不同尺寸颜色数量的商品加入购物车,购物车管理,地址管理,形 ...

  7. python写安卓app控制蓝牙_基于python实现蓝牙通信代码实例

    这篇文章主要介绍了基于python实现蓝牙通信代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 安装和示例 linux下安装 sudo apt ...

  8. Ch2r_ood_understanding 本文档为论文限定领域口语对话系统中超出领域话语的对话行为识别的部分实验代码。代码基于Python,需要用到的外部库有: Keras(搭建神经网络) S

    Ch2r_ood_understanding 本文档为论文限定领域口语对话系统中超出领域话语的对话行为识别的部分实验代码.代码基于Python,需要用到的外部库有: Keras(搭建神经网络) Sci ...

  9. 在线执行代码,线上代码执行,支持 php go woo lua luajit python perl ruby

    在线执行代码,线上代码执行,支持 php go woo lua luajit python perl ruby 在线执行编辑器

最新文章

  1. Compiling: main.cpp /bin/sh: g++: not found
  2. php后台开发工具有哪些,热门的 PHP 开发工具都有哪些?
  3. 多重背包2[二进制位优化]
  4. jsp中获取不到后台请求域中的值
  5. WPF实现仪表盘(刻度跟随)
  6. ELK+Kafka部署
  7. 锁表次数一般多大_「健身增肌」有些肌肉喜欢“大重量”,有些肌肉需要“高次数”...
  8. 自定义session,cookie
  9. windows 一键安装apache服务器 windows傻瓜式安装apache2 web服务器管理软件
  10. 东山里的传说——《荒原的呼唤》选载之四
  11. 2017-07-08 前端日报
  12. java 四大元注解_java中元注解有四个
  13. 《出版专业实务·初级(2020版)》学习笔记
  14. DevOps 实践指南
  15. android电影播放器,万能电影播放器2018最新版-万能电影播放器v1.0 安卓版-腾牛安卓网...
  16. 计算机专业可以评电力工程职称吗,电力工程类职称评审专业范围,你了解多少?...
  17. B站最近很火的damedane,unravel图片唱歌
  18. Eolink: 一站式 API 生产力工具
  19. 关于“差强人意”成语的误用
  20. uni-app修改页面背景色:

热门文章

  1. 【网络通信】select、poll、epoll
  2. 该模型在额定以下采用MTPA控制,速度环输出给定电流,然后代入MTPA得到dq电流,电压反馈环输出超前角进行弱磁
  3. moloch流量回溯_用moloch和elastic索引网络流量
  4. 杭州金田电磁流量计数据解析之读出累计总量
  5. 数组 和 集合的区别 尤其是ArrayList
  6. Go函数及与函数相关机制 【Go语言圣经笔记】
  7. 小白必看!数据库自学入门教程,免费的SQL认证课程
  8. 工控机IP地址规划 妙用保留地址 169.254.x.x
  9. 用PyCharm连接远程服务器,设置Python解释器时fail to connect解决办法
  10. 设置一个励志Mac锁屏短语吧!