|
发表于 2023-3-19 10:45:27
|
显示全部楼层
供参考:
- import tkinter as tk
- from tkinter import font
- import time
- def display_text(text):
- # 初始化窗口
- root = tk.Tk()
- root.geometry("500x300")
- root.configure(bg="black")
-
- # 设置字体和大小
- custom_font = font.Font(family="楷体", size=16)
-
- # 创建文本框并添加到窗口中
- text_widget = tk.Text(root, width = 10,wrap = "char",bg="black", fg="white", font=custom_font)
- text_widget.pack(expand=True, fill="both")
-
- # 将文本分割成段落
- paragraphs = text.split("\n")
-
- for paragraph in paragraphs:
-
- for character in map(''.join, zip(*(iter(paragraph),)*10)): # 注意这行,一行10个字就写10,目前我还没有想出什么办法判断一行最多可以放多少个字
- text_widget.insert(tk.END, "♡")
- text_widget.update()
- time.sleep(0.1)
-
- text_widget.delete("end-2c", tk.END)
-
- text_widget.insert(tk.END, character)
- text_widget.update()
-
- time.sleep(0.1)
-
- if float(text_widget.index("end")) > 7.0:
- text_widget.delete("1.0", "2.0")
- text_widget.insert(tk.END, " \n") # 注意这行
- text_widget.insert(tk.END, " \n")
- display_text("""一大段文本""" * 80)
复制代码 |
评分
-
参与人数 1 | 荣誉 +5 |
鱼币 +5 |
贡献 +3 |
收起
理由
|
TGgan
| + 5 |
+ 5 |
+ 3 |
谢谢,我已经解决啦,差不多就是这个以上,. |
查看全部评分
|