如何在不换行的情况下使用 Tkinter 文本小组件?
可使用 configure(**options)** 函数配置 Tkinter 文本小组件。我们可以利用它配置文本小组件的背景颜色、前景色、换行和其他属性。
文本小组件的 wrap 属性表示当检测到新的一行时,光标将改变其位置。然而,在 Tkinter 中,文本小组件可以按单词和字符换行。为了使我们的文本小组件保持在一行内,我们可以使用 wrap=None 属性。
范例
# Import the required libraries
from tkinter import *
import lorem
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add a Text widget
text=Text(win, width=60, height=20)
text.pack()
# Add Some text into it
text.insert(END,lorem.sentence())
# Configure the text widget to make the text sticky on one line
text.configure(wrap=None)
win.mainloop()输出
运行以上代码将显示一个文本小组件,其中文本将换行到 None。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP