title: Is there a function to export Treeview data into a PDF in Python?
body: <p>I have developed a program using Tkinter in Python which allows users to view the list of loaned items(Using the Search function to populate the Treeview)by a Company from the data stored in the Loan Table in MYSQL DB. The  I would like to include a functionality(Print Button) which allows the user to export that displayed data into a PDF. Does Python Tkinter has such functionality? Thanks.<a href="https://i.stack.imgur.com/gFP9p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gFP9p.png" alt="enter image description here" /></a></p>
  <pre><code>class tab_six(Frame):
  def __init__(self, *args, **kwargs):
      Frame.__init__(self, *args, **kwargs)
      
  
       #Creating a frame, frame2, on the window/canvas for the first tab
      frame6 = tk.LabelFrame(self, text=&quot;List of loaned items&quot;, bd=6) #Frame2 on the window/canvas
      frame6.grid(column=1, row=1, padx=40, pady=20, sticky='NSEW') #Positioning frame2
      self.grid_columnconfigure(1, weight=1) #Configuring the column for the main window/canvas
      self.grid_rowconfigure(1, weight=1) #Configuring the row for the main window/canvas
      
      #Creating LabelFrame in frame2
      upperframe = tk.LabelFrame(frame6, bd=0)
      upperframe.grid(column=0, row=0, sticky='W')
      frame6.rowconfigure(0, weight=0)
      frame6.columnconfigure(0, weight=1)
      
      middleframe= tk.LabelFrame(frame6, bd=5)
      middleframe.grid(column=0, row=1, sticky = &quot;NSEW&quot;)
      frame6.columnconfigure(0, weight=0)
      frame6. rowconfigure(1, weight=1)
      
      lowerframe = tk.LabelFrame(frame6, bd=0)
      lowerframe.grid(column=0, row=2)
      frame6.columnconfigure(0, weight=1)
      frame6. rowconfigure(2, weight=0)
      
      #Labels in frame2
      label31 = tk.Label(upperframe, text=&quot;Company Name:&quot;, relief='flat')
      label31.grid(column=0, row=0, padx=5, pady=5, sticky='W')
      label32 = tk.Label(upperframe, text=&quot;Asset ID:&quot;, relief='flat')
      label32.grid(column=0, row=1, padx=5, pady=5, sticky='W')
      
      #Combobox Widgets in frame2
      CompanyList = []
      command = &quot;SELECT DISTINCT`Company` from `Loan History` ORDER BY `Company` ASC&quot;
      mycursor.execute(command)
      company_result = mycursor.fetchall()
      
      for n in range(len(company_result)):
          company_result[n] = list(company_result[n])
          CompanyList.append(company_result[n][0])
  
      searchBox6 = ttk.Combobox(upperframe, width=22, values=CompanyList)
      searchBox6.grid(column=1, row=0, pady=5, sticky='W', ) #Positioning of the widget
      searchBox6.insert(0, &quot;Please select one&quot;)
      searchBox6.configure(state='readonly')
      
      
       #Creating treeview in frame2
      vsb = Scrollbar(middleframe,orient=&quot;vertical&quot;)
      hsb = Scrollbar(middleframe,orient=&quot;horizontal&quot;)
      databaseView6 = ttk.Treeview(middleframe, yscrollcommand=vsb.set, xscrollcommand=hsb.set)
      databaseView6.grid(column=0, row=0, sticky = &quot;NSEW&quot;)
      middleframe.columnconfigure(0, weight=1)
      middleframe.rowconfigure(0, weight=1)
      databaseView6[&quot;show&quot;] = &quot;headings&quot;
      databaseView6[&quot;columns&quot;] = (&quot;asset&quot;, &quot;type&quot;, &quot;name&quot;, &quot;company&quot;, &quot;email&quot;, &quot;contact&quot;, &quot;issue&quot;, &quot;date&quot;)
      vsb.configure(command=databaseView6.yview)
      hsb.configure(command=databaseView6.xview)
      vsb.grid(column=1, row=0, sticky=&quot;NS&quot;)
      hsb.grid(column=0, row=1, sticky=&quot;WE&quot;)
      
      #Treeview column headings
      databaseView6.heading(&quot;asset&quot;, text=&quot;Asset ID&quot;)
      databaseView6.column(&quot;asset&quot;, anchor= 'center', width=100)
      databaseView6.heading(&quot;type&quot;, text=&quot;Equipment Type&quot;)
      databaseView6.column(&quot;type&quot;, width=250)
      databaseView6.heading(&quot;name&quot;, text=&quot;Loanee&quot;)
      databaseView6.column(&quot;name&quot;, anchor='center', width=150)
      databaseView6.heading(&quot;company&quot;, text=&quot;Company&quot;)
      databaseView6.column(&quot;company&quot;, anchor='center', width=200)
      databaseView6.heading(&quot;email&quot;, text=&quot;Email&quot;)
      databaseView6.column(&quot;email&quot;, anchor='center', width=200)
      databaseView6.heading(&quot;contact&quot;, text=&quot;Contact&quot;)
      databaseView6.column(&quot;contact&quot;, anchor='center', width=100)
      databaseView6.heading(&quot;issue&quot;, text=&quot;Issue&quot;)
      databaseView6.column(&quot;issue&quot;, anchor='center', width=100)
      databaseView6.heading(&quot;date&quot;, text=&quot;Return&quot;)
      databaseView6.column(&quot;date&quot;, anchor='center', width=100)
      
      #Button Widgets in frame2
      btn4 = tk.Button(upperframe, width=7, text=&quot;Search&quot;, command=lambda:CSearch\
      (searchBox6, databaseView6))
      btn4.grid(column=2, row=0, padx=5, pady=5, sticky='W')
  def CSearch(search_Box, tree):
  find = search_Box.get()
      
  if (find != &quot;Please select one&quot;):
         
      command = (&quot;SELECT `Asset ID`, `Equipment Type`, `Name`, `Company`, `Email`, `Phone`, `Issue Timestamp`, `Return Timestamp` FROM `Loan History` WHERE `Company`=%s&quot;)
      mycursor.execute(command,(search_Box.get(),))
      myresult = mycursor.fetchall()
      array2 = []
      
      for n in range(len(myresult)):
          myresult[n] = list(myresult[n])
          array2.append(myresult[n])
                                                                                                                                                                                                                                                                                                                                                                  
      #Clear the current data in the table
      for x in tree.get_children():
          tree.delete(x)
      
      for each in array2:
          tree.insert(&quot;&quot;, &quot;end&quot;, values = [each[0], each[1], each[2], each[3], each[4], each[5], each[6], each[7]], tags=each[0])
                                       
      tree.selection_set(tree.tag_has(find))
     
  else:
      valueErrorMessage = &quot;Please select one from the drop down menu&quot;
      tkinter.messagebox.showerror(&quot;Error&quot;, valueErrorMessage) 
  </code></pre>