如何删除文本小部件末尾的换行符 (\n)? [英] How can I remove newline character (\n) at the end of Text widget?

查看:48
本文介绍了如何删除文本小部件末尾的换行符 (\n)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Tkinter GUI.

I am working on a Tkinter GUI.

我想知道如何删除文本小部件末尾的换行符 (\n)?这让我的应用看起来很难看,我不想要这个.

I am wondering how can I remove newline character (\n) at the end of Text widget? It's making my App looking ugly I don't want this.

示例代码是:

from tkinter import *
from tkinter import ttk

window = Tk()
window.title('Advanced Calculator v0.9')
window.geometry('500x400')
window.resizable(False, False)

window.configure(background='black')

hist_t = Text(window, background='black', height='7', foreground='red', font='Verdana', highlightcolor='grey', highlightthickness=1, relief='solid')

Label(window, text='History:', background='black', foreground='red').pack(pady=3, anchor='w')

hist_t.pack(fill='x', padx=3)

hist_t.insert('end', '4 + 4 = 8\n2 + 2 = 4\n5 + 3 = 8\n10 + 13 = 23\n30 + 10 = 40\n12 + 8 = 20')

window.mainloop()

谢谢.

推荐答案

您的问题似乎不是任何额外的换行符,只是您将其配置为显示 7 行,但您只插入了 6 行.如果您设置高度为 6 你不会看到这个空行.

Your problem doesn't appear to be any extra newlines, it's simply that you configured it to show 7 lines but you're only inserting 6. If you set the height to 6 you won't see this blank line.

这篇关于如何删除文本小部件末尾的换行符 (\n)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆