title: Saving datas from treeview to csv file tkinter python
body: <p>Hello I wrote a program in tkinter (Python) and I have a problem with saving datas from treeview to file CSV. I dont use any sql database. Just problem with saving content of treeview. Does anybody please have any idea how to save content of treeview to CSV file according to my code?</p>
  <pre><code>from tkinter import *
  from tkinter import ttk
  from tkinter.filedialog import asksaveasfile
  from tkinter.filedialog import askopenfile
  from tkcalendar import Calendar,DateEntry
  import csv
  from tkinter.messagebox import showinfo,askquestion
      root = Tk()
  root.title(&quot;Medicine database&quot;)
  
  one = StringVar()
  two = StringVar()
  three = StringVar()
  four = StringVar()
      def quit():
      MsgBox = askquestion('Exit Application','Are you sure you want to exit the application',icon = 'warning')
      if MsgBox == 'yes':
          root.destroy()
  def save():
      with open(&quot;new.csv&quot;,&quot;w&quot;,newline='') as f:
          w=csv.writer(f, delimiter='\t')
          w.writerow(tree.get_children())
          showinfo(&quot;Save to CSV file&quot;,&quot;File was saved&quot;)
  def add_medicine():
      row = tree.insert(&quot;&quot;,END,values=(e0.get(),e1.get(),e2.get(),cal1.get()))
      e0.delete(0,END)
      e1.delete(0,END)
      e2.delete(0,END)
  def select(event):
      try:
          cursor = tree.focus()
          content = tree.item(cursor)
          row = content[&quot;values&quot;]
          one.set(row[0])
          two.set(row[1])
          three.set(row[2])
      except IndexError:
          pass
  def delete_all():
      for i in tree.get_children():
          tree.delete(i)
  def edit():
      try:
          x = tree.selection()[0]
          for item in x:
              tree.item(x,values=(e0.get(),e1.get(),e2.get(),cal1.get()))
      except IndexError:
          pass
  def remove_item():
      selected_items = tree.selection()[0]
      tree.delete(selected_items)
  def open_CSV():
      with open(&quot;new.csv&quot;) as myfile:
          csvread = csv.reader(myfile,delimiter=&quot;,&quot;)
          for i in csvread:
              print(i)
  
  tree = ttk.Treeview(root,height=25,selectmode=EXTENDED)
  tree[&quot;columns&quot;]=(&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;four&quot;)
  tree.column(&quot;one&quot;,width=120)
  tree.column(&quot;two&quot;,width=160)
  tree.column(&quot;three&quot;,width=130)
  tree.column(&quot;four&quot;,width=160)
  tree.heading(&quot;one&quot;, text=&quot;Numer seryjny leku&quot;)
  tree.heading(&quot;two&quot;, text=&quot;Nazwa Leku&quot;)
  tree.heading(&quot;three&quot;, text=&quot;Ilość ampułek&quot;)
  tree.heading(&quot;four&quot;,text=&quot;Data ważności&quot;)
  tree[&quot;show&quot;]=&quot;headings&quot;
  root.mainloop()
  </code></pre>