bunkinet
bunkinet

Reputation: 103

_tkinter.TclError: invalid command name ".63347536"

When closing Python3 program I get the above error code. Still the program works fine.

import sqlite3
import tkinter   #import gui library

global T1,T2,T3,T4,T5,T6,List1
global BCDB,curVehicle
BCDB = sqlite3.connect('DB.sqlite')
curVehicle=BCDB.cursor()

def CreateWindow():
    global main1
    main1=tkinter.Tk()
    main1.wm_state('zoomed')
    main1.title="System"

def CreateUI():
    global T1,T2,T3,T4,T5,T6,List1
    CMDMkTable=tkinter.Button(main1,text="Create Table")
    CMDDlTable=tkinter.Button(main1,text="Delete Table")
    CMDAddRec=tkinter.Button(main1,text="Add Data")
    CMDChngCol=tkinter.Button(main1,text="ChangeColor")#command=lambda: 
    ChangeColor(T6.get())
    CMDgetData=tkinter.Button(main1,text="Get Data",command=getData)

    tkinter.Label(main1, text="Car Code").grid(row=1)
    T1=tkinter.Entry(main1)
    T1.grid(row=1,column=1)
    tkinter.Label(main1, text="Lic No").grid(row=2)
    T2=tkinter.Entry(main1)
    T2.grid(row=2,column=1)
    tkinter.Label(main1, text="Make").grid(row=3)
    T3=tkinter.Entry(main1)
    T3.grid(row=3,column=1)
    tkinter.Label(main1, text="Model").grid(row=4)
    T4=tkinter.Entry(main1)
    T4.grid(row=4,column=1)
    tkinter.Label(main1, text="No. of Seats").grid(row=5)
    T5=tkinter.Entry(main1)
    T5.grid(row=5,column=1)
    T6=tkinter.Entry(main1)
    T6.grid(row=0)


    CMDMkTable.grid(row=0,column=2)
    CMDDlTable.grid(row=1,column=2)
    CMDAddRec.grid(row=6, column=1)
    CMDChngCol.grid(row=6,column=3)
    CMDgetData.grid(row=6,column=0)


    List1=tkinter.Listbox(main1,height=10,width=30)
    List1.winfo_exists()
    List1.grid(row=7, column=1)

    main1.mainloop()

def getData():
    curVehicle.execute('SELECT * FROM Vehicle') 
    Result=curVehicle.fetchall()
    #print(Result)
    j=0
    for i in Result:
            List1.insert(j,i)
            j+=1                        

CreateWindow()
CreateUI()
getData()
BCDB.close()

When closing this program I get following error:

Traceback (most recent call last):
File "I:\bls.py", line 78, in <module>    
getData()
File "I:\bls.py", line 68, in getData
List1.insert(j,i)
File "C:\Program Files\Python\lib\tkinter\__init__.py", line 2645, in insert
self.tk.call((self._w, 'insert', index) + elements)
_tkinter.TclError: invalid command name ".51825488"

Yet the GetData function properly insert all records to List1. Why is this exception generating?

Upvotes: 0

Views: 637

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385800

getData() isn't called until after the main window is destroyed. It tries to insert something into the listbox but the listbox no longer exists.

In the error message, .63347536 is the internal name of the listbox widget. Internally there is a command with the same name, hence the error.

Upvotes: 1

Related Questions