I am trying to bind two different functions to two different parts of the treeview. the command deleteItem
should only apply to rows, whilst the columnselect
function should only apply to columns. When I run this code the second bind overrides the first.
import tkinter as tk
from tkinter import messagebox
from tkinter.font import Font
from tkinter import scrolledtext
from tkinter import ttk
def deleteItem(a):
print("In delete Item")
curItem = AttendanceView.focus()
inter_var = AttendanceView.item(curItem)
ListValues = inter_var['values']
print(ListValues)
def columnnameselect(q):
tk.messagebox.showinfo("","You didn't press a row")
# AttendanceView Specific Table Components
Attendance=tk.Tk()
AttendanceView = ttk.Treeview(Attendance)
AttendanceView["columns"] = ("firstname", "secondname","patrol","present")
AttendanceView.grid(row=3, column=1)
AttendanceView.heading("#0", text="", anchor="w")
AttendanceView.column("#0", anchor="center", width=5, stretch=tk.NO)
AttendanceView.heading("firstname", text="First Name", anchor="w")
AttendanceView.column("firstname", anchor="center", width=80)
AttendanceView.heading("secondname", text="Second Name", anchor="w")
AttendanceView.column("secondname", anchor="center", width=90)
AttendanceView.heading("patrol", text="Patrol", anchor="w")
AttendanceView.column("patrol", anchor="center", width=80)
AttendanceView.heading("present", text="Present", anchor="w")
AttendanceView.column("present", anchor="center", width=80)
AttendanceView.grid(row=3, column=1, columnspan=5)
AttendanceView.bind('<ButtonRelease-1>', deleteItem)
AttendanceView.bind('<ButtonRelease-1>', columnnameselect)
AttendanceViewScrollbar = ttk.Scrollbar(Attendance, orient="vertical", command=AttendanceView.yview)
AttendanceView.configure(yscroll=AttendanceViewScrollbar.set)
AttendanceViewScrollbar.grid(row=3, column=6, sticky="ns")
AttendanceView.insert("", "end", text="", values=(("Ethel",("Kennedy"),("Cow"),(""))))
AttendanceView.insert("", "end", text="", values=(("Jack",("Kennedy"),("Lion"),(""))))
AttendanceView.insert("", "end", text="", values=(("Bobby",("Kennedy"),("Zebra"),(""))))
The desired outcome:
- When a column is selected,
columnselect
is run. - When a row is selected,
deleteItem
is run.
Any help would be appreciated.