'invalid command name ".!frame2.!frame2.!treeview" tkinter
I'm creating list of account program in tkinter where I can add, edit, and delete an account in the tree table. However, updating data in tree table gives me trouble. When updating data, it is automatically selected from the table and it will reflected to another window for editing. After editing, the updating window destroys as well as the main window by clicking the update button. The main window will open again to refresh data in the table. However, it produces an error "invalid command name ".!frame2.!frame2.!treeview" in the main class.
Here is the piece of code for displaying data function in the main class:
class Interface:
def displayData(self):
connect = mysql.connect(
host = "localhost",
username = "root",
port ="3306",
password="",
database = "accountstorage",
)
cursor = connect.cursor()
sql = "SELECT * FROM table1 ORDER BY type"
cursor.execute(sql)
result = cursor.fetchall()
self.table.tag_configure('oddrow',background = "#001221")
self.table.tag_configure('evenrow',background = "#002645")
self.count = 0
if len(result) !=0 :
self.table.delete(*self.table.get_children())
for row in result:
if self.count % 2 != 0:
self.table.insert('',tk.END, values = row, tags = ('oddrow',))
else:
self.table.insert('',tk.END, values = row, tags = ('evenrow',))
self.count +=1
connect.commit()
connect.close()
def destroy(self):
self.window.destroy()
Here is the code from outside class from different file to perform data update
class Action:
def updateData(self):
updateID = self.id
updateAcc = self.acc.get()
updateName = self.accountEntry.get()
updateEmail = self.emailEntry.get()
updatePass = self.passwordEntry.get()
updatePhone = self.phoneEntry.get()
updateType = self.typeList.get()
if (updateAcc =="" or updateName == "" or updateEmail== ""or updatePass == ""or updatePhone == "" ):
MessageBox.showerror("Error","Please Complete the Following Form")
else:
connect = mysql.connect(
host = "localhost",
username = "root",
port ="3306",
password="",
database = "accountstorage",
)
cursor = connect.cursor()
sql = "UPDATE table1 SET account = %s,accountname = %s,email = %s,password = %s,contact = %s,type = %s WHERE id = %s"
val = (updateAcc,updateName,updateEmail,updatePass,updatePhone,updateType,updateID)
cursor.execute(sql,val)
#print (updateType,"1")
print(self.type,"1")
connect.commit()
connect.close()
self.quit()
self.myInstance = myMain.Interface()
self.myInstance.destroy()
self.myInstance.displayData()
def quit(self):
self.window.destroy()
I tried to use try catch to verify the error and it shows ' can't invoke event command: application has been destroyed while executing"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
