Я знаю, что, возможно, я делаю глупую ошибку, но есть ли причина, по которой это не работает? Я пытаюсь удалить строку в древовидной структуре, нажав на строку, а затем на кнопку удаления, но по какой-то причине атрибут tv не входит в функцию без ошибки.
class pageDeleteStaff(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text = "Delete Staff", font = NORMAL_FONT)
label.pack()
tv = ttk.Treeview(self, height = 10, columns = ("StaffID, Forename, Surname, Wage, NIN, Account Name, Account Number, Contract Hours, Usercode, Passcode"))
tv.pack()
tv.heading("#0", text = "StaffID")
tv.heading("#1", text = "Forename")
tv.heading("#2", text = "Surname")
tv.heading("#3", text = "Wage(£)")
tv.heading("#4", text = "NIN")
tv.heading("#5", text = "Account Name")
tv.heading("#6", text = "Account Number")
tv.heading("#7", text = "Contract Hours")
tv.heading("#8", text = "Usercode")
tv.heading("#9", text = "Passcode")
tv.column("#0", width = 100)
tv.column("#1", width = 170)
tv.column("#2", width = 170)
tv.column("#3", width = 150)
tv.column("#4", width = 170)
tv.column("#5", width = 200)
tv.column("#6", width = 150)
tv.column("#7", width = 150)
tv.column("#8", width = 150)
tv.column("#9", width = 150)
conn = sqlite3.connect('subway.db')
c = conn.cursor()
c.execute("SELECT * FROM staff")
staffData = c.fetchall()
for row in staffData:
tv.insert("", "end", text=row[0], values=row[1:])
print(row)
conn.close()
button4 = tk.Button(self, text="Delte", bg = 'grey', fg = 'black', font = SMALL_FONT, height = 2, width = 14,
command = self.deleteRow(controller))
button4.pack()
button4 = tk.Button(self, text="Menu", bg = 'grey', fg = 'black', font = SMALL_FONT, height = 2, width = 14,
command = lambda: controller.show_frame(pageLabour))
button4.pack()
def deleteRow(self, controller):
currentItem = self.tv.focus()
item = tv.item(currentItem)
if item.get("text") == "":
messagebox.showerror("ERROR", "No member of staff selected!")
else:
staffID = int(item.get("text"))
result = messagebox.askyesno("Are you sure?", "Are you sure you would like to delete?")
Я получаю ошибка атрибута при вызове тв в функцию.
Вот мой код