我正在创建一个简单的程序,在tkinter的列表框中显示文本。有时我要显示的文本比列表框大,因此它不在屏幕上。我想知道是否有办法让文本在屏幕下方开始新行而不是离开屏幕。
代码
from tkinter import *
root = Tk()
text = Text(root, width = 50, height=15, bg="#2C2F33", fg="white",wrap=WORD)
text.grid(row=0, column=0, padx=10)
while True:
message = input("Enter a message: ")
text.insert(INSERT, message)
root.mainloop()
问题:
预期结果
非常感谢所有帮助!
Listbox小部件是一个菜单项,可供选择。列表框项目不可能分布在多行或多行中。
您应该使用另一个名为Text的小部件
from tkinter import *
root = Tk()
message = "This message is too long to display on the listbox. I hope that someone will help me find a solution to this problem."
text = Text(root, width = 50, height=15, bg="#2C2F33", fg="white",wrap=WORD)
text.insert(INSERT, message)
text.grid(row=0, column=0, padx=10)
root.mainloop()
注意:wrap:此选项控制显示过宽的行。设置wrap = WORD,它将在最后一个单词之后换行会适合的。使用默认行为,wrap = CHAR,太长会损坏任何字符。