Home > Software design >  _tkinter.TclError: Item 1 1 not found
_tkinter.TclError: Item 1 1 not found

Time:07-26

i am triying to get boolean values from db and if True check icon comes in and 0 uncheck icon, but it looks like i cant loop over it in a correct way.. i have made a for loop that is connected with db but it shows empty.

def employee():
global email_field, checkfield

conn= sqlite3.connect('schoonschip.db')
cursorr = conn.cursor()
cursorr.execute("SELECT  email, rowid, selection FROM employee ")
employe = cursorr.fetchall()

trv.delete(*trv.get_children())

for i in employe:
    item = trv.item(trv.focus(i))
    print(item)
    if item['values'][1] == 1:
        trv.insert('', 'end', values=i,  tags='check')
    else:
        trv.insert('', 'end', values=i, tags='uncheck')

conn.commit()
conn.close()
employee()  

CodePudding user response:

If you want to check the value of the selection column in the database table, you need to change the for loop as below:

for i in employe:
    # i[2] is the value of 'selection' column in the result set
    if i[2] == 1:
        trv.insert('', 'end', values=i, tags='check')
    else:
        trv.insert('', 'end', values=i, tags='uncheck')
  • Related