Sandyagu R
Sandyagu R

Reputation: 43

Showing a syntax error when I tried to do a project with treeview

Can anyone please tell me what's the issue with this code

import tkinter as tk
from tkinter import messagebox
from tkinter import ttk
from registration import DBConnect
class ListTicket():
    def __init__(self):
        self.db=DBConnect()
        self.root=tk.Tk()
        tv=ttk.Treeview(self.root)
        tv.pack()
        tv.heading("#0",text="ID")
        tv.column=("NAME")
        tv.column = ("GENDER")
        tv.column = ("COMMENTS")
        tv.heading("NAME",text="NAME")
        tv.heading("GENDER",text="GENDER")
        tv.heading("COMMENTS",text="COMMENTS")
        cursor =self.db.Show()
        for row in cursor:
            tv.insert("","end","#{}".format(row["ID"],text=row["ID"])) #1
            tv.set("#{}".format(row["ID"],column="NAME",value=row["name"]) #2
            tv.set("#{}".format(row["ID"],column="GENDER",value=row["gender"]) #3
            tv.set("#{}".format(row["ID"],column="COMMENTS",value=row["comment"]) #4
       self.root.mainloop()

I am getting a syntax error with line 2,3,4. I am taking values from a database.

Upvotes: 0

Views: 150

Answers (1)

Delrius Euphoria
Delrius Euphoria

Reputation: 15098

As far as your syntax error is concerned:

for row in cursor:
    tv.insert("","end","#{}".format(row["ID"],text=row["ID"])) #1
    tv.set("#{}".format(row["ID"],column="NAME",value=row["name"])) #2
    tv.set("#{}".format(row["ID"],column="GENDER",value=row["gender"])) #3
    tv.set("#{}".format(row["ID"],column="COMMENTS",value=row["comment"])) #4

You forgot to close the parenthesis at the end of every tv.set().

Upvotes: 2

Related Questions