Как получить строку символа в текстовом виджете в tkinter?

#python-3.x #tkinter

#python-3.x #tkinter

Вопрос:

У меня есть текстовый виджет, который содержит:

 This is the first line
This is the Second line
This is the Third line
  

и как я извлекаю весь символ, который разделяется каждой строкой?, пожалуйста, помогите мне

Комментарии:

1. Вы читали документацию для текстового виджета? Вы можете найти ответ там.

Ответ №1:

 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: ['This is the first line', 'This is the Second line', 'This is the Third line', '']

В конце остается пустой элемент, но вы можете удалить его, если используете:

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

Это приведет к следующему: ['This is the first line', 'This is the Second line', 'This is the Third line']