有没有办法在tkinter中设置列表框的固定行长度?因此,当插入较大尺寸的字符串时,它会继续到下一行吗?
答案 0 :(得分:0)
不,没有办法让列表框中的项目包裹到两行或更多行。
答案 1 :(得分:0)
查看比最宽的列表框更宽的行的唯一方法是使用水平滚动条,如下所示:
#!/usr/bin/env python3
from tkinter import *
from tkinter import ttk
root = Tk()
listo = Listbox(root, background='white', width=100)
listo.grid(column=0, row=0, sticky=(N, W, E, S))
ybar = ttk.Scrollbar(root, orient=VERTICAL, command=listo.yview)
ybar.grid(column=1, row=0, sticky=(N, W, E, S))
xbar = ttk.Scrollbar(root, orient=HORIZONTAL, command=listo.xview)
xbar.grid(column=0, row=1, columnspan=2, sticky=(N, W, E, S))
listo["yscrollcommand"] = ybar.set
listo["xscrollcommand"] = xbar.set
listo.insert('end', "When, in the course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume, among the nations of the earth, that separate and equal station to which the laws of Nature and of Nature's God entitle them...")
root.mainloop()