Python 3.x 如何在tkinter中的文本小部件中获取字符行?

Python 3.x 如何在tkinter中的文本小部件中获取字符行?,python-3.x,tkinter,Python 3.x,Tkinter,我有一个包含以下内容的文本小部件: This is the first line This is the Second line This is the Third line 以及如何检索每行分隔的整个字符?请帮助我 from tkinter import Tk, Text, END root = Tk() text = Text(root) text.insert(0.0, """This is the first line This is the Secon

我有一个包含以下内容的文本小部件:

This is the first line
This is the Second line
This is the Third line
以及如何检索每行分隔的整个字符?请帮助我

from tkinter import Tk, Text, END

root = Tk()
text = Text(root)
text.insert(0.0,
"""This is the first line
This is the Second line
This is the Third line""")
text.pack()
lines = text.get(0.0, END).split("\n") #That's the line you need
print(lines)

root.mainloop()
CLI输出:
[‘这是第一行’、‘这是第二行’、‘这是第三行’、“”]

它会在末尾留下一个空白项,但如果使用以下选项,则可以将其删除:

lines = text.get(0.0, END).split("\n")[:-1]

这将输出以下内容:
[‘这是第一行’、‘这是第二行’、‘这是第三行’]

您阅读了文本小部件的文档了吗?你可以在那里找到答案。