slowprint-tool 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: slowprint-tool
3
+ Version: 3.1.0
4
+ Summary: 慢速打字机效果工具库(逐字打印、彩色、闪烁、进度条、滚动、Tkinter动画)
5
+ Author: noahwzy
6
+ Author-email: 1988464660@163.com
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: colorama
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: license
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # slowprint
24
+ Python 慢速打字机效果工具库:逐字打印、随机节奏、彩色输出、闪烁、进度条、滚动文本,并支持 Tkinter Label 打字动画。
25
+
26
+ ## 功能
27
+ - **控制台函数**(纯 stdout,无需 GUI):
28
+ - `print_slow` 逐字慢速打印
29
+ - `print_slow_rand` 随机节奏慢速打印(带大停顿模拟人类打字)
30
+ - `print_slow_color` 单色慢速打印
31
+ - `print_slow_multi_color` 多段彩色慢速打印
32
+ - `print_slow_lines` 逐行慢速打印
33
+ - `slow_text` 原地逐字推进(`\r`)并返回结果
34
+ - `overwrite_slow` 逐字写出覆盖效果
35
+ - `delete_slow` 逐字删除效果
36
+ - `blink_text` 文本闪烁
37
+ - `progress_bar` 进度条动画
38
+ - `scroll_text` 文本横向滚动
39
+ - **Tkinter 类** `LabelSlowText`:驱动 `tkinter.Label` 的打字动画,全部方法带 `con_` 前缀,tkinter 延迟导入。
40
+
41
+ ## 安装
42
+ ```bash
43
+ pip install slowprint-tool
44
+ ```
45
+ > 依赖 `colorama`(自动安装)。
46
+
47
+ ## 使用示例
48
+
49
+ ### 控制台慢速打印
50
+ ```python
51
+ import slowprint as sp
52
+
53
+ sp.print_slow("你好,世界!", delay=0.1) # 逐字慢打印
54
+ sp.print_slow_color("红色文字", color="red") # 彩色慢打印
55
+ sp.print_slow_rand("随机节奏打字", base_delay=0.08) # 随机节奏
56
+ sp.progress_bar(total=50, speed=0.03) # 进度条
57
+ sp.blink_text("注意!", times=3) # 闪烁
58
+ sp.scroll_text("横向滚动文本", width=15) # 滚动
59
+ ```
60
+
61
+ ### 彩色组合
62
+ ```python
63
+ import slowprint as sp
64
+
65
+ sp.print_slow_multi_color([("红", "red"), ("绿", "green"), ("蓝", "blue")])
66
+ ```
67
+
68
+ ### Tkinter Label 打字动画
69
+ ```python
70
+ import tkinter as tk
71
+ from slowprint import LabelSlowText
72
+
73
+ root = tk.Tk()
74
+ label = tk.Label(root, text="", font=("", 18))
75
+ label.pack()
76
+ anim = LabelSlowText(label) # 传入 tkinter.Label 对象
77
+ anim.con_print_slow("正在逐字显示……", delay=0.08)
78
+ root.mainloop()
79
+ ```
80
+
81
+ ## API 文档
82
+
83
+ ### 控制台函数
84
+ | 函数 | 说明 | 关键参数 |
85
+ |------|------|----------|
86
+ | `print_slow(text, delay=0.08, end="\n")` | 逐字慢打印 | `delay` 字符间隔秒数 |
87
+ | `print_slow_rand(text, base_delay=0.08, fluctuate=0.04, big_pause_prob=0.07, big_pause=0.25, end="\n")` | 随机节奏打印,偶发大停顿 | 模拟真实打字 |
88
+ | `print_slow_color(text, color="green", delay=0.08, end="\n")` | 单色慢打印 | `color` 取 `COLORS` 键名 |
89
+ | `print_slow_multi_color(text_color_list, delay=0.08, end="\n")` | 多段彩色打印 | 参数为 `[(文本, 颜色), ...]` |
90
+ | `print_slow_lines(text_list, delay_line=0.6, char_delay=0.07)` | 逐行慢打印 | 行间停顿 `delay_line` |
91
+ | `slow_text(text, delay=0.08)` | 原地推进并返回字符串 | 返回完整文本 |
92
+ | `overwrite_slow(text, delay=0.08)` | 逐字写出(覆盖同位置) | |
93
+ | `delete_slow(text, delay=0.12)` | 逐字删除 | |
94
+ | `blink_text(text, times=3, interval=0.4)` | 闪烁 `times` 次 | |
95
+ | `progress_bar(total, speed=0.05, bar_len=30, end_print='加载完成!')` | 进度条 | `total` 步数 |
96
+ | `scroll_text(text, width=20, delay=0.1)` | 横向滚动 | `width` 显示宽度 |
97
+
98
+ ### COLORS
99
+ 颜色字典,可用颜色:`black/red/green/yellow/blue/purple/cyan/white/reset`。
100
+
101
+ ### LabelSlowText(Tkinter 类)
102
+ 传入 `tkinter.Label` 实例。方法均带 `con_` 前缀:`con_print_slow`、`con_print_slow_rand`、`con_overwrite_slow`、`con_delete_slow`、`con_blink_text`、`con_progress_bar`、`con_scroll_text`,另含 `cancel()` 取消当前动画。tkinter 仅在该类被实例化时延迟加载。
103
+
104
+ ## 说明
105
+ - 控制台函数仅依赖 `sys/time/random`,不强制要求 GUI;`LabelSlowText` 才需要 Tkinter。
106
+ - 依赖 `colorama`,用于跨平台 ANSI 颜色支持(Windows 下也能正常显示彩色)。
107
+
108
+ ## 版本日志
109
+ - 3.1.0:彩色、随机节奏、多段彩色、Tkinter Label 动画、进度条、滚动等全套打字机效果
110
+
111
+ ## 许可证
112
+ MIT
@@ -0,0 +1,90 @@
1
+ # slowprint
2
+ Python 慢速打字机效果工具库:逐字打印、随机节奏、彩色输出、闪烁、进度条、滚动文本,并支持 Tkinter Label 打字动画。
3
+
4
+ ## 功能
5
+ - **控制台函数**(纯 stdout,无需 GUI):
6
+ - `print_slow` 逐字慢速打印
7
+ - `print_slow_rand` 随机节奏慢速打印(带大停顿模拟人类打字)
8
+ - `print_slow_color` 单色慢速打印
9
+ - `print_slow_multi_color` 多段彩色慢速打印
10
+ - `print_slow_lines` 逐行慢速打印
11
+ - `slow_text` 原地逐字推进(`\r`)并返回结果
12
+ - `overwrite_slow` 逐字写出覆盖效果
13
+ - `delete_slow` 逐字删除效果
14
+ - `blink_text` 文本闪烁
15
+ - `progress_bar` 进度条动画
16
+ - `scroll_text` 文本横向滚动
17
+ - **Tkinter 类** `LabelSlowText`:驱动 `tkinter.Label` 的打字动画,全部方法带 `con_` 前缀,tkinter 延迟导入。
18
+
19
+ ## 安装
20
+ ```bash
21
+ pip install slowprint-tool
22
+ ```
23
+ > 依赖 `colorama`(自动安装)。
24
+
25
+ ## 使用示例
26
+
27
+ ### 控制台慢速打印
28
+ ```python
29
+ import slowprint as sp
30
+
31
+ sp.print_slow("你好,世界!", delay=0.1) # 逐字慢打印
32
+ sp.print_slow_color("红色文字", color="red") # 彩色慢打印
33
+ sp.print_slow_rand("随机节奏打字", base_delay=0.08) # 随机节奏
34
+ sp.progress_bar(total=50, speed=0.03) # 进度条
35
+ sp.blink_text("注意!", times=3) # 闪烁
36
+ sp.scroll_text("横向滚动文本", width=15) # 滚动
37
+ ```
38
+
39
+ ### 彩色组合
40
+ ```python
41
+ import slowprint as sp
42
+
43
+ sp.print_slow_multi_color([("红", "red"), ("绿", "green"), ("蓝", "blue")])
44
+ ```
45
+
46
+ ### Tkinter Label 打字动画
47
+ ```python
48
+ import tkinter as tk
49
+ from slowprint import LabelSlowText
50
+
51
+ root = tk.Tk()
52
+ label = tk.Label(root, text="", font=("", 18))
53
+ label.pack()
54
+ anim = LabelSlowText(label) # 传入 tkinter.Label 对象
55
+ anim.con_print_slow("正在逐字显示……", delay=0.08)
56
+ root.mainloop()
57
+ ```
58
+
59
+ ## API 文档
60
+
61
+ ### 控制台函数
62
+ | 函数 | 说明 | 关键参数 |
63
+ |------|------|----------|
64
+ | `print_slow(text, delay=0.08, end="\n")` | 逐字慢打印 | `delay` 字符间隔秒数 |
65
+ | `print_slow_rand(text, base_delay=0.08, fluctuate=0.04, big_pause_prob=0.07, big_pause=0.25, end="\n")` | 随机节奏打印,偶发大停顿 | 模拟真实打字 |
66
+ | `print_slow_color(text, color="green", delay=0.08, end="\n")` | 单色慢打印 | `color` 取 `COLORS` 键名 |
67
+ | `print_slow_multi_color(text_color_list, delay=0.08, end="\n")` | 多段彩色打印 | 参数为 `[(文本, 颜色), ...]` |
68
+ | `print_slow_lines(text_list, delay_line=0.6, char_delay=0.07)` | 逐行慢打印 | 行间停顿 `delay_line` |
69
+ | `slow_text(text, delay=0.08)` | 原地推进并返回字符串 | 返回完整文本 |
70
+ | `overwrite_slow(text, delay=0.08)` | 逐字写出(覆盖同位置) | |
71
+ | `delete_slow(text, delay=0.12)` | 逐字删除 | |
72
+ | `blink_text(text, times=3, interval=0.4)` | 闪烁 `times` 次 | |
73
+ | `progress_bar(total, speed=0.05, bar_len=30, end_print='加载完成!')` | 进度条 | `total` 步数 |
74
+ | `scroll_text(text, width=20, delay=0.1)` | 横向滚动 | `width` 显示宽度 |
75
+
76
+ ### COLORS
77
+ 颜色字典,可用颜色:`black/red/green/yellow/blue/purple/cyan/white/reset`。
78
+
79
+ ### LabelSlowText(Tkinter 类)
80
+ 传入 `tkinter.Label` 实例。方法均带 `con_` 前缀:`con_print_slow`、`con_print_slow_rand`、`con_overwrite_slow`、`con_delete_slow`、`con_blink_text`、`con_progress_bar`、`con_scroll_text`,另含 `cancel()` 取消当前动画。tkinter 仅在该类被实例化时延迟加载。
81
+
82
+ ## 说明
83
+ - 控制台函数仅依赖 `sys/time/random`,不强制要求 GUI;`LabelSlowText` 才需要 Tkinter。
84
+ - 依赖 `colorama`,用于跨平台 ANSI 颜色支持(Windows 下也能正常显示彩色)。
85
+
86
+ ## 版本日志
87
+ - 3.1.0:彩色、随机节奏、多段彩色、Tkinter Label 动画、进度条、滚动等全套打字机效果
88
+
89
+ ## 许可证
90
+ MIT
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ from setuptools import setup, find_packages
2
+ from pathlib import Path
3
+
4
+ this_directory = Path(__file__).parent
5
+ long_description = (this_directory / "README.md").read_text(encoding="utf-8-sig")
6
+
7
+ NAME = "slowprint-tool"
8
+ VERSION = "3.1.0"
9
+ DESCRIPTION = "慢速打字机效果工具库(逐字打印、彩色、闪烁、进度条、滚动、Tkinter动画)"
10
+ AUTHOR = "noahwzy"
11
+ AUTHOR_EMAIL = "1988464660@163.com"
12
+ INSTALL_REQUIRES = ["colorama"]
13
+
14
+ setup(
15
+ name=NAME,
16
+ version=VERSION,
17
+ description=DESCRIPTION,
18
+ long_description=long_description,
19
+ long_description_content_type="text/markdown",
20
+ author=AUTHOR,
21
+ author_email=AUTHOR_EMAIL,
22
+ packages=find_packages(include=["slowprint", "slowprint.*"]),
23
+ install_requires=INSTALL_REQUIRES,
24
+ python_requires=">=3.8",
25
+ license="MIT",
26
+ classifiers=[
27
+ "Programming Language :: Python :: 3",
28
+ "Operating System :: OS Independent",
29
+ ],
30
+ )
@@ -0,0 +1,299 @@
1
+ import time
2
+ import sys
3
+ import random
4
+ import colorama
5
+
6
+ colorama.init(autoreset=True)
7
+ __version__ = "3.1.0"
8
+
9
+ COLORS = {
10
+ "black": "\033[30m",
11
+ "red": "\033[31m",
12
+ "green": "\033[32m",
13
+ "yellow": "\033[33m",
14
+ "blue": "\033[34m",
15
+ "purple": "\033[35m",
16
+ "cyan": "\033[36m",
17
+ "white": "\033[37m",
18
+ "reset": "\033[0m"
19
+ }
20
+
21
+
22
+ # ------------------------------
23
+ # 【模块顶层:控制台函数,无对象直接调用,不加前缀,纯stdout,不需要tkinter】
24
+ # ------------------------------
25
+ def print_slow(text: str, delay: float = 0.08, end: str = "\n") -> None:
26
+ if not text:
27
+ sys.stdout.write(end)
28
+ sys.stdout.flush()
29
+ return
30
+ for char in text:
31
+ sys.stdout.write(char)
32
+ sys.stdout.flush()
33
+ time.sleep(delay)
34
+ sys.stdout.write(end)
35
+ sys.stdout.flush()
36
+
37
+
38
+ def print_slow_rand(text: str, base_delay: float = 0.08, fluctuate: float = 0.04,
39
+ big_pause_prob: float = 0.07, big_pause: float = 0.25, end: str = "\n") -> None:
40
+ if not text:
41
+ sys.stdout.write(end)
42
+ sys.stdout.flush()
43
+ return
44
+ for char in text:
45
+ sys.stdout.write(char)
46
+ sys.stdout.flush()
47
+ if random.random() < big_pause_prob:
48
+ t = big_pause
49
+ else:
50
+ t = base_delay + random.uniform(-fluctuate, fluctuate)
51
+ time.sleep(max(0.01, t))
52
+ sys.stdout.write(end)
53
+ sys.stdout.flush()
54
+
55
+
56
+ def print_slow_color(text: str, color: str = "green", delay: float = 0.08, end: str = "\n") -> None:
57
+ if not text:
58
+ sys.stdout.write(end)
59
+ sys.stdout.flush()
60
+ return
61
+ c = COLORS.get(color, COLORS["reset"])
62
+ sys.stdout.write(c)
63
+ for char in text:
64
+ sys.stdout.write(char)
65
+ sys.stdout.flush()
66
+ time.sleep(delay)
67
+ sys.stdout.write(COLORS["reset"])
68
+ sys.stdout.write(end)
69
+ sys.stdout.flush()
70
+
71
+
72
+ def print_slow_multi_color(text_color_list: list, delay: float = 0.08, end: str = "\n") -> None:
73
+ for seg_text, seg_color in text_color_list:
74
+ c = COLORS.get(seg_color, COLORS["reset"])
75
+ sys.stdout.write(c)
76
+ for char in seg_text:
77
+ sys.stdout.write(char)
78
+ sys.stdout.flush()
79
+ time.sleep(delay)
80
+ sys.stdout.write(COLORS["reset"])
81
+ sys.stdout.write(end)
82
+ sys.stdout.flush()
83
+
84
+
85
+ def print_slow_lines(text_list: list, delay_line: float = 0.6, char_delay: float = 0.07) -> None:
86
+ for line in text_list:
87
+ print_slow(line, char_delay)
88
+ time.sleep(delay_line)
89
+
90
+
91
+ def slow_text(text: str, delay: float = 0.08) -> str:
92
+ res = ""
93
+ for char in text:
94
+ res += char
95
+ sys.stdout.write(f"\r{res}")
96
+ sys.stdout.flush()
97
+ time.sleep(delay)
98
+ print()
99
+ return res
100
+
101
+
102
+ def overwrite_slow(text: str, delay: float = 0.08) -> None:
103
+ for i in range(len(text) + 1):
104
+ sys.stdout.write(f"\r{text[:i]}")
105
+ sys.stdout.flush()
106
+ time.sleep(delay)
107
+ print()
108
+
109
+
110
+ def delete_slow(text: str, delay: float = 0.12) -> None:
111
+ for i in range(len(text), -1, -1):
112
+ sys.stdout.write(f"\r{text[:i]}")
113
+ sys.stdout.flush()
114
+ time.sleep(delay)
115
+ print()
116
+
117
+
118
+ def blink_text(text: str, times: int = 3, interval: float = 0.4) -> None:
119
+ if not text or times <= 0:
120
+ return
121
+ blank = " " * len(text)
122
+ for _ in range(times):
123
+ sys.stdout.write(f"\r{text}")
124
+ sys.stdout.flush()
125
+ time.sleep(interval)
126
+ sys.stdout.write(f"\r{blank}")
127
+ sys.stdout.flush()
128
+ time.sleep(interval)
129
+ sys.stdout.write(f"\r{text}\n")
130
+ sys.stdout.flush()
131
+
132
+
133
+ def progress_bar(total: int, speed: float = 0.05, bar_len: int = 30, end_print='加载完成!') -> None:
134
+ if total <= 0:
135
+ sys.stdout.write(f"\r进度: |{'-'*bar_len}| 100.0%\n{end_print}\n")
136
+ sys.stdout.flush()
137
+ return
138
+ for i in range(total + 1):
139
+ rate = i / total
140
+ block = int(bar_len * rate)
141
+ bar = "#" * block + "-" * (bar_len - block)
142
+ sys.stdout.write(f"\r进度: |{bar}| {rate*100:.1f}%")
143
+ sys.stdout.flush()
144
+ time.sleep(speed)
145
+ print(f"\n{end_print}")
146
+
147
+
148
+ def scroll_text(text: str, width: int = 20, delay: float = 0.1) -> None:
149
+ if not text:
150
+ return
151
+ pad = " " * width
152
+ full = text + pad + text
153
+ for i in range(len(text)+width):
154
+ show = full[i:i+width]
155
+ sys.stdout.write(f"\r{show}")
156
+ sys.stdout.flush()
157
+ time.sleep(delay)
158
+ print()
159
+
160
+
161
+ # ------------------------------
162
+ # Tkinter Label类:全部内部方法加 con_ 前缀;tkinter延迟导入
163
+ # ------------------------------
164
+ class LabelSlowText:
165
+ """Tkinter Label打字动画,类内全部方法带 con_ 前缀"""
166
+ def __init__(self, label_widget):
167
+ # 延迟导入tkinter,只有实例化才加载tk
168
+ import tkinter as tk
169
+ if not isinstance(label_widget, tk.Label):
170
+ raise TypeError("需要传入tkinter.Label对象")
171
+ self.label = label_widget
172
+ self._job_id = None
173
+
174
+ def cancel(self):
175
+ if self._job_id is not None:
176
+ self.label.after_cancel(self._job_id)
177
+ self._job_id = None
178
+
179
+ def con_print_slow(self, text: str, delay: float = 0.08):
180
+ self.cancel()
181
+ chars = list(text)
182
+ output = []
183
+ def _step(idx):
184
+ if idx >= len(chars):
185
+ self.label["text"] = "".join(output)
186
+ self._job_id = None
187
+ return
188
+ output.append(chars[idx])
189
+ self.label["text"] = "".join(output)
190
+ self._job_id = self.label.after(int(delay*1000), _step, idx+1)
191
+ _step(0)
192
+
193
+ def con_print_slow_rand(self, text: str, base_delay: float = 0.08, fluctuate: float = 0.04,
194
+ big_pause_prob: float = 0.07, big_pause: float = 0.25):
195
+ self.cancel()
196
+ chars = list(text)
197
+ output = []
198
+ def _step(idx):
199
+ if idx >= len(chars):
200
+ self.label["text"] = "".join(output)
201
+ self._job_id = None
202
+ return
203
+ output.append(chars[idx])
204
+ self.label["text"] = "".join(output)
205
+ if random.random() < big_pause_prob:
206
+ t = big_pause
207
+ else:
208
+ t = base_delay + random.uniform(-fluctuate, fluctuate)
209
+ t = max(0.01, t)
210
+ self._job_id = self.label.after(int(t*1000), _step, idx+1)
211
+ _step(0)
212
+
213
+ def con_overwrite_slow(self, text: str, delay: float = 0.08):
214
+ self.cancel()
215
+ def _step(i):
216
+ if i > len(text):
217
+ self._job_id = None
218
+ return
219
+ self.label["text"] = text[:i]
220
+ self._job_id = self.label.after(int(delay*1000), _step, i+1)
221
+ _step(0)
222
+
223
+ def con_delete_slow(self, text: str, delay: float = 0.12):
224
+ self.cancel()
225
+ def _step(i):
226
+ if i < 0:
227
+ self.label["text"] = ""
228
+ self._job_id = None
229
+ return
230
+ self.label["text"] = text[:i]
231
+ self._job_id = self.label.after(int(delay*1000), _step, i-1)
232
+ _step(len(text))
233
+
234
+ def con_blink_text(self, text: str, times: int = 3, interval: float = 0.4):
235
+ self.cancel()
236
+ count = 0
237
+ def _toggle(show: bool):
238
+ nonlocal count
239
+ if count >= times:
240
+ self.label["text"] = text
241
+ self._job_id = None
242
+ return
243
+ if show:
244
+ self.label["text"] = text
245
+ else:
246
+ self.label["text"] = ""
247
+ count += 1
248
+ self._job_id = self.label.after(int(interval*1000), _toggle, not show)
249
+ _toggle(True)
250
+
251
+ def con_progress_bar(self, total: int, speed: float = 0.05, bar_len: int = 30, end_print='加载完成!'):
252
+ self.cancel()
253
+ if total <= 0:
254
+ self.label["text"] = f"进度: |{'-'*bar_len}| 100.0%\n{end_print}"
255
+ return
256
+ current = 0
257
+ def _step():
258
+ nonlocal current
259
+ current += 1
260
+ rate = current / total
261
+ block = int(bar_len * rate)
262
+ bar = "#" * block + "-" * (bar_len - block)
263
+ self.label["text"] = f"进度: |{bar}| {rate*100:.1f}%"
264
+ if current > total:
265
+ self.label["text"] += f"\n{end_print}"
266
+ self._job_id = None
267
+ return
268
+ self._job_id = self.label.after(int(speed*1000), _step)
269
+ _step()
270
+
271
+ def con_scroll_text(self, text: str, width: int = 20, delay: float = 0.1):
272
+ self.cancel()
273
+ pad = " " * width
274
+ full = text + pad + text
275
+ max_i = len(text)+width
276
+ def _step(i):
277
+ if i >= max_i:
278
+ self._job_id = None
279
+ return
280
+ self.label["text"] = full[i:i+width]
281
+ self._job_id = self.label.after(int(delay*1000), _step, i+1)
282
+ _step(0)
283
+
284
+
285
+ __all__ = [
286
+ "print_slow",
287
+ "print_slow_rand",
288
+ "print_slow_color",
289
+ "print_slow_multi_color",
290
+ "print_slow_lines",
291
+ "slow_text",
292
+ "overwrite_slow",
293
+ "delete_slow",
294
+ "blink_text",
295
+ "progress_bar",
296
+ "scroll_text",
297
+ "COLORS",
298
+ "LabelSlowText"
299
+ ]
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: slowprint-tool
3
+ Version: 3.1.0
4
+ Summary: 慢速打字机效果工具库(逐字打印、彩色、闪烁、进度条、滚动、Tkinter动画)
5
+ Author: noahwzy
6
+ Author-email: 1988464660@163.com
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: colorama
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: license
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # slowprint
24
+ Python 慢速打字机效果工具库:逐字打印、随机节奏、彩色输出、闪烁、进度条、滚动文本,并支持 Tkinter Label 打字动画。
25
+
26
+ ## 功能
27
+ - **控制台函数**(纯 stdout,无需 GUI):
28
+ - `print_slow` 逐字慢速打印
29
+ - `print_slow_rand` 随机节奏慢速打印(带大停顿模拟人类打字)
30
+ - `print_slow_color` 单色慢速打印
31
+ - `print_slow_multi_color` 多段彩色慢速打印
32
+ - `print_slow_lines` 逐行慢速打印
33
+ - `slow_text` 原地逐字推进(`\r`)并返回结果
34
+ - `overwrite_slow` 逐字写出覆盖效果
35
+ - `delete_slow` 逐字删除效果
36
+ - `blink_text` 文本闪烁
37
+ - `progress_bar` 进度条动画
38
+ - `scroll_text` 文本横向滚动
39
+ - **Tkinter 类** `LabelSlowText`:驱动 `tkinter.Label` 的打字动画,全部方法带 `con_` 前缀,tkinter 延迟导入。
40
+
41
+ ## 安装
42
+ ```bash
43
+ pip install slowprint-tool
44
+ ```
45
+ > 依赖 `colorama`(自动安装)。
46
+
47
+ ## 使用示例
48
+
49
+ ### 控制台慢速打印
50
+ ```python
51
+ import slowprint as sp
52
+
53
+ sp.print_slow("你好,世界!", delay=0.1) # 逐字慢打印
54
+ sp.print_slow_color("红色文字", color="red") # 彩色慢打印
55
+ sp.print_slow_rand("随机节奏打字", base_delay=0.08) # 随机节奏
56
+ sp.progress_bar(total=50, speed=0.03) # 进度条
57
+ sp.blink_text("注意!", times=3) # 闪烁
58
+ sp.scroll_text("横向滚动文本", width=15) # 滚动
59
+ ```
60
+
61
+ ### 彩色组合
62
+ ```python
63
+ import slowprint as sp
64
+
65
+ sp.print_slow_multi_color([("红", "red"), ("绿", "green"), ("蓝", "blue")])
66
+ ```
67
+
68
+ ### Tkinter Label 打字动画
69
+ ```python
70
+ import tkinter as tk
71
+ from slowprint import LabelSlowText
72
+
73
+ root = tk.Tk()
74
+ label = tk.Label(root, text="", font=("", 18))
75
+ label.pack()
76
+ anim = LabelSlowText(label) # 传入 tkinter.Label 对象
77
+ anim.con_print_slow("正在逐字显示……", delay=0.08)
78
+ root.mainloop()
79
+ ```
80
+
81
+ ## API 文档
82
+
83
+ ### 控制台函数
84
+ | 函数 | 说明 | 关键参数 |
85
+ |------|------|----------|
86
+ | `print_slow(text, delay=0.08, end="\n")` | 逐字慢打印 | `delay` 字符间隔秒数 |
87
+ | `print_slow_rand(text, base_delay=0.08, fluctuate=0.04, big_pause_prob=0.07, big_pause=0.25, end="\n")` | 随机节奏打印,偶发大停顿 | 模拟真实打字 |
88
+ | `print_slow_color(text, color="green", delay=0.08, end="\n")` | 单色慢打印 | `color` 取 `COLORS` 键名 |
89
+ | `print_slow_multi_color(text_color_list, delay=0.08, end="\n")` | 多段彩色打印 | 参数为 `[(文本, 颜色), ...]` |
90
+ | `print_slow_lines(text_list, delay_line=0.6, char_delay=0.07)` | 逐行慢打印 | 行间停顿 `delay_line` |
91
+ | `slow_text(text, delay=0.08)` | 原地推进并返回字符串 | 返回完整文本 |
92
+ | `overwrite_slow(text, delay=0.08)` | 逐字写出(覆盖同位置) | |
93
+ | `delete_slow(text, delay=0.12)` | 逐字删除 | |
94
+ | `blink_text(text, times=3, interval=0.4)` | 闪烁 `times` 次 | |
95
+ | `progress_bar(total, speed=0.05, bar_len=30, end_print='加载完成!')` | 进度条 | `total` 步数 |
96
+ | `scroll_text(text, width=20, delay=0.1)` | 横向滚动 | `width` 显示宽度 |
97
+
98
+ ### COLORS
99
+ 颜色字典,可用颜色:`black/red/green/yellow/blue/purple/cyan/white/reset`。
100
+
101
+ ### LabelSlowText(Tkinter 类)
102
+ 传入 `tkinter.Label` 实例。方法均带 `con_` 前缀:`con_print_slow`、`con_print_slow_rand`、`con_overwrite_slow`、`con_delete_slow`、`con_blink_text`、`con_progress_bar`、`con_scroll_text`,另含 `cancel()` 取消当前动画。tkinter 仅在该类被实例化时延迟加载。
103
+
104
+ ## 说明
105
+ - 控制台函数仅依赖 `sys/time/random`,不强制要求 GUI;`LabelSlowText` 才需要 Tkinter。
106
+ - 依赖 `colorama`,用于跨平台 ANSI 颜色支持(Windows 下也能正常显示彩色)。
107
+
108
+ ## 版本日志
109
+ - 3.1.0:彩色、随机节奏、多段彩色、Tkinter Label 动画、进度条、滚动等全套打字机效果
110
+
111
+ ## 许可证
112
+ MIT
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ slowprint/__init__.py
5
+ slowprint_tool.egg-info/PKG-INFO
6
+ slowprint_tool.egg-info/SOURCES.txt
7
+ slowprint_tool.egg-info/dependency_links.txt
8
+ slowprint_tool.egg-info/requires.txt
9
+ slowprint_tool.egg-info/top_level.txt