python-3.x - 如何在 tkinter 的文本小部件中获取一行字符?
问题描述
我的 Text 小部件包含:
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()
命令行输出:['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']
推荐阅读
- vue.js - 检查调度vuex是否完成
- amazon-web-services - 如何存储运动流以进行播放
- server - 我应该使用什么树莓派来托管 Discord Bot?
- powershell - 自托管 vsts 构建代理上的 signtool 命令未完成
- wordpress - Wordpress:为管理员用户加载特定的 CSS
- python - 从没有 homedir 的用户的 tex 生成 pdf
- c++ - 为什么'static'关键字允许函数返回正确的引用?
- android - Retrofit 2 错误响应处理
- mbed - 我可以将简易连接库与 Roving Network XV Wifi 模块一起使用吗?
- python - python SELECT COLUMN FROM TABLE WHERE COLUMN = self.variable