Python Forum

Full Version: Treeview - How to lock columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi every one,

i read this documentation for lock the resizable column and headers too
but not work.

here is my code
# coding:utf-8
#version 3.x python
# DOC --> https://www.tcl.tk/man/tcl8.5/TkCmd/ttk_treeview.htm#M17

from tkinter import *
from tkinter.ttk import *
import sqlite3

# Connexion DB
con = sqlite3.connect("HE.db")
cur = con.cursor()
cur.execute("SELECT id, HE_Nom, HE_Prop, HE_Dosage FROM HE ORDER BY HE_Nom ASC")
mData = cur.fetchall()
print("Nombre d'enregistrement", len(mData))

win = Tk()
win.title('Huiles Essentiels')
win.geometry("820x559+30+30")

# Frame
frm = Frame(win)
frm.place(x=10, y=10, width=600, height=150)

# Treeview & Y Scrollbar Vertical & X Scrollbar Vertical
scrollbar_y = Scrollbar(frm)
scrollbar_y.place(x=580, y=2, height=149)

tv=Treeview(frm, selectmode="browse", columns=(1,2,3), show="headings", height="5", yscrollcommand=scrollbar_y.set)
    # En-tĂȘte
tv.heading(1, text="HE", anchor=W)
tv.heading(2, text="Description", anchor=W)
tv.heading(3, text="Dosage", anchor=W)

tv.column('#1', width=150, minwidth=150, stretch=False)
tv.column('#2', width=350, minwidth=350, stretch=False)
tv.column('#3', width=50, minwidth=50, stretch=False)
tv.place(x=2, y=2, width=578, height=180)
# tv.columnconfigure(1, pad=10)
# tv.columnconfigure(2, weight=0)
# tv.columnconfigure(3, weight=0)

scrollbar_y.config(command=tv.yview)

    # Affichage
a = 0
for i in mData:
    tv.insert('', 'end', text=i[0], values=(i[1],i[2],i[3]))
    print("Index", i[0])
    a = a + 1
print("Nombre d'enregistrement", a)


win.mainloop()
thank you in advance for your time