0

I'm currently learning Tkinter and working on a small SQLite database application for managing client information. I've encountered a couple of issues that I'm seeking assistance with:

  • Extra Column in Tkinter Treeview:

    In my application, I've set up a ttk.Treeview to display client information. However, I notice that there is an extra column appearing in the table, and I'm unsure why this is happening.

  • Alignment Issue in SQLite Database:

    Additionally, when I save information to the SQLite database and retrieve it to display in the ttk.Treeview, there seems to be an alignment issue. The data is not displaying correctly in the respective columns, and there appears to be a misalignment.

I've tried adjusting column widths and alignments, but the problems persist. I'm reaching out to the community for guidance on identifying and resolving these issues.


def lista_frame2(self):
    self.listaCli = ttk.Treeview(self.frame_2, height=3, columns=("col0", "col1", "col2", "col3"))
    self.listaCli.heading("#0", text="Código", anchor=CENTER)
    self.listaCli.heading("col1", text="Nome", anchor=CENTER)
    self.listaCli.heading("col2", text="Telefone", anchor=CENTER)
    self.listaCli.heading("col3", text="Cidade", anchor=CENTER)

    self.listaCli.column("#0", width=50, anchor=CENTER)
    self.listaCli.column("col1", width=50, anchor=CENTER)
    self.listaCli.column("col2", width=50, anchor=CENTER)
    self.listaCli.column("col3", width=60, anchor=CENTER)

    self.listaCli.place(relx= 0.025, rely= 0.05, relwidth= 0.92, relheight= 0.90)
    
    self.scrollLista = Scrollbar(self.frame_2, orient = 'vertical')
    self.listaCli.configure(yscroll=self.scrollLista.set)
    self.scrollLista.place(relx= 0.945, rely= 0.05, relwidth= 0.03, relheight= 0.90)
    self.listaCli.bind("<Double-1>", self.OnDoubleClick)

screenshot

What I've Tried:

  1. Adjusted column widths in the ttk.Treeview to ensure they are appropriate for the content.
  2. Set anchor=CENTER for column headings to center-align the text.
  3. Checked for any extra spaces or characters in the data retrieved from the SQLite database.

Expectation:

  1. I expected the ttk.Treeview to display only the specified columns without any additional ones.
  2. I expected the data retrieved from the SQLite database to be correctly aligned within their respective columns in the ttk.Treeview.
1
  • Shouldn't "#0" be "col0"? Commented Nov 23, 2023 at 17:02

1 Answer 1

0

You need to:

  • set show="headings" when creating the treeview
  • use "col0" instead of "#0" in .heading(...) and .column(...)
def lista_frame2(self):
    self.listaCli = ttk.Treeview(self.frame_2, height=3,
                                 columns=("col0", "col1", "col2", "col3"), 
                                 show="headings")
    self.listaCli.heading("col0", text="Código", anchor=CENTER)
    ...
    self.listaCli.column("col0", width=50, anchor=CENTER)
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.