This is my sample code. I want the items typed in the entry to be inserted to the treeview when the enter button is pressed. Im new to python and tkinter and there is not much tuts about treeview.
class PurchaseEntry(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
PurchaseEntry.configure(self, bg='white')
label = ttk.Label(self, text='Purchase Entry', font=LARGE_FONT2)
label.grid(row=0, columnspan=3, sticky='w')
purchase_entry = ttk.Label(self, text='Purchase Entry:')
purchase_entry.grid(row=1, column=0)
self.entry_val = tk.StringVar()
self.entry_1 = ttk.Entry(self, width=100, textvariable=self.entry_val)
self.entry_1.grid(row=1, column=2, columnspan=2, sticky='w')
self.entry_1.focus()
self.entry_btn = ttk.Button(self,text='Enter', command=self.insert_value)
self.entry_btn.grid(row=1, column=4, columnspan=2, sticky='w')
self.chat1 = ttk.Treeview(self)
chat1 = ttk.Treeview( self, height=28, columns=('dose', 'date modified'), selectmode="extended")
chat1.heading('#0', text='item', anchor=tk.CENTER)
chat1.heading('#1', text='dose', anchor=tk.CENTER)
chat1.heading('#2', text='date modified', anchor=tk.CENTER)
chat1.column('#1', stretch=tk.YES, minwidth=50, width=100)
chat1.column('#2', stretch=tk.YES, minwidth=50, width=120)
chat1.column('#0', stretch=tk.YES, minwidth=50, width=400)
chat1.grid(row=2, column=2, columnspan=4, sticky='nsew')
def insert_value(self):
value = self.entry_val.get()
# Inserts data written in the entry box to the treeview widget when Enter button is pressed.
# Clears the Entry box, ready for another data entry.
self.entry_1.delete(0, 'end')
self.chat1.insert('WHAT SHOULD I GIVE AS AN ARGUMENT?')
What should I pass as an argument? Or is treeview the right widget for this or can someone suggest a widget suitable for this issue? thanks