【发布时间】:2015-11-09 08:05:16
【问题描述】:
如何删除 tkinter Scrolledtext 小部件内每行末尾的空白空间?
输入
每行末尾没有空格的txt文件。
代码
def openCommand():
ftypes = [('Text files', '*.txt')] # allow only txt files
filePath = tkFileDialog.askopenfile(parent=root,mode='rb',title=' Select a file', filetypes = ftypes)
if filePath != None:
contents = str(filePath.read()).strip()
contents = contents.rstrip()
contents = contents.lstrip()
textPad.insert('1.0',contents.strip())
输出
在文本板中插入文件内容:
textPad = ScrolledText(root, width=100, height=30, undo=True)
textPad.pack()
我会在每一行的末尾看到一个空白区域。
注意
我已经尝试了所有与 Python 字符串修剪相关的东西。
【问题讨论】: