|
发表于 2023-3-19 09:35:29
|
显示全部楼层
你的代码我试了一下,如果那一大段文本有换行符的话是没有问题的
- import tkinter as tk
- from tkinter import font
- import time
- # 初始化窗口
- root = tk.Tk()
- def display_text(text):
- 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:
- # 分割段落为单个字符
- characters = list(paragraph)
-
- for character in characters:
- 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("""一大段文本\n""" * 18) # 注意这里
- root.mainloop()
复制代码 |
|