I want to to fill my window with, say, labels and I want them to wrap once the column would be bigger than the current window (or rather parent frame) size.

I've tried using the grid layout, but then I have to calculate the size of the content of each row myself, to know when to put the next element in the next row.

The reason I ask, is because I want to create some sort of tiled file icons.

Or asked differently, is there something like Swing's FlowLayout for TkInter?

有帮助吗?

解决方案

What I do when I want something like this is use the text widget for a container. The text widget can have embedded widgets, and they wrap just like text. As long as your widgets are all the same height the effect is pretty nice.

For example (cut and pasted from the question at the author's request):

textwidget = tk.Text(master)
textwidget.pack(side=tk.LEFT, fill=tk.BOTH)
for f in os.listdir('/tmp'):
    textwidget.window_create(tk.INSERT, window=tk.Label(textwidget, text=f))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top