如何减小树视图的列宽?
How can I reduce Tree view' s column's width?
我想减小列的宽度以适合。正如您在此处 (https://i.stack.imgur.com/VK6w8.png) 看到的那样,table 是不规则的,有些列不可见。我该如何解决这个问题?
这是我的代码:
def show():
# connect to database if exist or if doesnt exit create one
conn= sqlite3.connect("Books_table.bd")
#create cursors
Cursor = conn.cursor()
Cursor.execute("SELECT * , oid FROM books")
records = Cursor.fetchall()
Query_window = Toplevel()
Query_window.title("Show Table ...")
Frm = Frame(Query_window)
Frm.pack()
Table = ttk.Treeview(Frm , column = (1,2,3,4,5,6,7,8) , show = "headings" , height = 5 )
Table.pack()
Table.heading(1 , text = "Book name")
Table.heading(2 , text = "Book number")
Table.heading(3 , text = "Book writer")
Table.heading(4 , text = "Book subject")
Table.heading(5 , text = "Quantity")
Table.heading(6 , text = "Borrower")
Table.heading(7 , text = "Return date")
Table.heading(8 , text = "Availability")
# insert values to the table
for record in records:
Table.insert("", "end" , value = record )
#Commit changes
conn.commit()
#close database
conn.close()
您可以使用 column() 方法设置 Treeview 列的宽度。
...
Table.heading(1, text="Book name")
Table.column(1, width=50)
...
我想减小列的宽度以适合。正如您在此处 (https://i.stack.imgur.com/VK6w8.png) 看到的那样,table 是不规则的,有些列不可见。我该如何解决这个问题?
这是我的代码:
def show():
# connect to database if exist or if doesnt exit create one
conn= sqlite3.connect("Books_table.bd")
#create cursors
Cursor = conn.cursor()
Cursor.execute("SELECT * , oid FROM books")
records = Cursor.fetchall()
Query_window = Toplevel()
Query_window.title("Show Table ...")
Frm = Frame(Query_window)
Frm.pack()
Table = ttk.Treeview(Frm , column = (1,2,3,4,5,6,7,8) , show = "headings" , height = 5 )
Table.pack()
Table.heading(1 , text = "Book name")
Table.heading(2 , text = "Book number")
Table.heading(3 , text = "Book writer")
Table.heading(4 , text = "Book subject")
Table.heading(5 , text = "Quantity")
Table.heading(6 , text = "Borrower")
Table.heading(7 , text = "Return date")
Table.heading(8 , text = "Availability")
# insert values to the table
for record in records:
Table.insert("", "end" , value = record )
#Commit changes
conn.commit()
#close database
conn.close()
您可以使用 column() 方法设置 Treeview 列的宽度。
...
Table.heading(1, text="Book name")
Table.column(1, width=50)
...