Maliang 轻量级 UI 框架技术文档
1. 安装指南
系统要求
- Python 版本必须 ≥ 3.10
安装方式
通过 pip 包管理器安装:
pip install maliang
依赖项
核心依赖仅包含:
typing-extensions(自动安装)
2. 项目使用说明
框架特点
- 基于 tkinter 的轻量级 UI 框架
- 所有 UI 元素均通过 Canvas 绘制实现
- 简洁的 API 设计
基础使用示例
from maliang import Maliang
app = Maliang(width=800, height=600, title="Demo")
def on_draw():
app.background(255)
app.circle(400, 300, 50, filled_color=(255, 0, 0))
app.regist_event('on_draw', on_draw)
app.run()
3. 项目 API 使用文档
核心类
Maliang 类
Maliang(
width: int, # 窗口宽度
height: int, # 窗口高度
title: str = "", # 窗口标题
fps: int = 60 # 帧率控制
)
常用绘图方法
| 方法 | 参数 | 说明 |
|---|---|---|
background() | (r, g, b) | 设置背景色 |
circle() | x, y, radius, stroke_width, stroke_color, filled_color | 绘制圆形 |
rect() | x, y, width, height, stroke_width, stroke_color, filled_color | 绘制矩形 |
line() | x1, y1, x2, y2, stroke_width, stroke_color | 绘制直线 |
事件注册
app.regist_event(event_type: str, callback: Callable)
支持事件类型:
on_draw: 每帧绘制事件on_mouse_clicked: 鼠标点击事件on_key_pressed: 键盘按下事件
4. 项目安装方式补充
开发版安装
如需安装最新开发版本:
pip install git+https://github.com/Xiaokang2022/maliang.git
验证安装
安装后可通过以下命令验证:
python -c "import maliang; print(maliang.__version__)"
注意事项
- 在 Linux 系统上可能需要额外安装 tkinter 开发包
- 建议使用虚拟环境安装以避免依赖冲突
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



