0
from Tkinter import *

root = Tk()
root.title("Help")

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)

help_message = 'This is the help menu. Please scroll through the menu to find the answer to your question'

listbox = Listbox(root)
listbox.pack()
listbox.insert(END, help_message)

listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)

mainloop()

当我运行此代码时,文本超出了列表框的边界。有没有我可以添加的参数,以便我可以让文本换行到下一行。我不在乎单词的一部分是否被截断。我试图使列表框更大,但文本仍然没有换行。

谢谢

4

1 回答 1

0

使用Text小部件而不是Listbox. Text小部件有wrap选项。(无,字符,字)

from Tkinter import *

root = Tk()
root.title("Help")

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)

help_message = 'This is the help menu. Please scroll through the menu to find the answer to your question'

txt = Text(root, wrap=WORD) # wrap=CHAR, wrap=NONE
txt.pack(expand=1, fill=BOTH)
txt.insert(END, help_message)

txt.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=txt.yview)

mainloop()
于 2013-07-03T02:23:37.430 回答