calculator/README.md
2025-04-19 23:51:48 +08:00

89 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 简易计算器GUI程序
![Calculator Screenshot](screenshot.png) <!-- 需添加实际截图 -->
[![Python Version](https://img.shields.io/badge/python-3.7%2B-blue)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## 功能特性
- **四则运算**:支持加(+)、减(-)、乘(×)、除(÷)基本运算
- **连续计算**:自动保留计算结果用于后续运算
- **智能显示**
- 自动去除小数点后多余的零
- 大数字自动适应显示区域
- **错误处理**
- 除零错误检测与提示
- 无效操作拦截
- 异常崩溃防护
- **交互设计**
- 退格键(←)支持
- 一键清零(C)功能
- 实时输入反馈
- **界面特性**
- 半透明窗口效果
- 响应式布局
- 中文宋体显示
## 快速开始
### 环境要求
- Python 3.7+
- Tkinter通常随Python默认安装
### 安装与运行
```bash
1. 克隆仓库
git clone https://git.forling.cn/luxuekun/calculator.git
2. 进入项目目录
cd calculator
3. 运行程序
python calculator.py
```
## 技术细节
### 技术栈
- **核心框架**: Python标准库 Tkinter
- **状态管理**: 全局变量跟踪模式
- **错误处理**: Try/Except异常捕获机制
- **界面布局**: Grid网格布局系统
### 项目结构
```python
calculator.py
├── 全局状态变量 # current_input, first_operand, operator
├── 样式配置常量 # COLORS, FONT, LAYOUT
├── 事件处理函数 # on_number_click, on_operator_click, calculate等
├── UI构建模块 # 结果显示区、操作按钮矩阵、等号按钮
└── 主程序循环 # root.mainloop()
```
## 版本历史
| 版本号 | 作者 | 发布日期 | 主要变更 |
|--------|----|------------|----------------------|
| v1.0.0 | 鲁豫 | 2025-04-15 | 初始版本,实现基本加减乘除法功能 |
## 贡献指南
欢迎通过以下方式参与项目改进:
1. 提交Issue报告问题
2. Fork仓库并提交Pull Request
3. 优化代码注释或文档
**开发团队**
- developer鲁豫 \<2085520973@qq.com>
- Code ReviewerXuekun Lu \<luxuekun@forling.cn>
## 学习资源
- [Tkinter官方文档](https://docs.python.org/3/library/tkinter.html)
- [Python异常处理指南](https://docs.python.org/3/tutorial/errors.html)
- [GUI设计最佳实践](https://learn.microsoft.com/zh-cn/windows/win32/uxguide/guidelines)
## 许可证
本项目基于 [MIT License](LICENSE) 开源