I'd like to insert data into a specific column of my ttk treeview widget. The users only input is a scanner, so I have to parse each code to determine which column it goes into. Right now, the parseData() function runs on pressing Enter, so I would like to take care of the insert there.
I have tried using the treeview.set(item, column, new_value), but it falls apart when inserting into a blank row.
class MainGUI:
def __init__(self, master):
self.master = master
self.data_view = ttk.Treeview(master)
self.data_view['columns'] = ["Date", "Item 1", "Item 2", "Item 3", "Item 4", "Source", "Destination", "Cart #",]
self.data_view['show'] = 'headings'
self.data_view.heading("Date", text="Date")
self.data_view.heading("Item 1", text="Item 1")
self.data_view.heading("Item 2", text="Item 2")
self.data_view.heading("Item 3", text="Item 3")
self.data_view.heading("Item 4", text="Item 4")
self.data_view.heading("Source", text="Source")
self.data_view.heading("Destination", text="Destination")
self.data_view.heading("Cart #", text="Cart #")
self.data_view.pack()
self.scan_entry = ttk.Entry(master)
self.scan_entry.pack()
self.scan_entry.bind('<Return>', self.parseEntry)
self.scan_entry.focus()
self.close_button = tk.Button(master, text="Close", command=self.adminLogout, width=15, height=5)
self.close_button.pack(anchor='se')
def parseEntry(self,event):
#INSERT self.scan_entry.get() into #ITEM 1 column, not date volumn
#If contains certain characters, maybe insert into Source or Destination
self.scan_entry.delete(0,'end')
Ideally, I'd like to be able to insert into the blank tree to any column, or in some cases grab what is selected, then change the value based on input.
self.data_view.insert('', 'end', values=('', self.scan_entry.get()))what you want?