请教要如何解决ttk的Treeview列宽和边框线闭合
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
root.title(‘text’)
root.geometry(‘800x400’)
frame = tk.LabelFrame(root, text=’分析区’, font=(‘宋体’, 10), fg=’red’, labelanchor=’n’, bd=1, height=140, width=600,
relief=’groove’)
frame.pack(side=’left’, pady=2, padx=2)
frame.pack_propagate(0)
fram1 = tk.Frame(frame, width=20, height=20)
fram1.pack(side=’left’)
mark = [str(i) for i in range(1, 21)]
table = ttk.Treeview(frame, columns=mark, height=5, style=’Treeview’, show=’headings’)
for j in range(len(mark)):
table.heading(column=mark[j], text=mark[j], anchor=’center’)
table.column(j, minwidth=0, width=28, anchor=’center’, stretch=tk.NO)
table.pack()
root.mainloop()
The
cid
for methodColumn
should be themark[j]
,j+1
orf'#{j+1}'
, notj
.It means that you didn’t set the width for column
'20'
, and the default width is 200 pixels, so the treeview will exceed the visible range of FRAME.Of course, you can remove the option `width=600` from the `frame`, also the statement `frame.pack_propagate(0)`.