title: Show output of Python script in Tkinter GUI
body: <p>I am new to python &amp; requesting help from experts in this community. I am trying to display the output of the following script in my Tkinter GUI. I have followed many solutions provided on the StackOverflow, but unfortunately, I am unable to implement those solutions in my code. I need help in displaying the output of the following script in my Tkinter GUI. So I can display the output in a Tkinter widget.</p>
  
  <pre><code>import os
  import tkinter as tk
  import cv2
  import numpy as np
  from PIL import Image
  from PIL import ImageTk
  
  class Difference_Button(Sample_Button, Button):
     def on_click_diff_per_button(self, diff_per):
        threshold = 0.8  # set threshold
         resultsDirectory = 'Data/Differece_images'
         sourceDirectory = os.fsencode('Data/images')
         templateDirectory = os.fsencode('Data/Sample_images')
         detectedCount = 0
  
         for file in os.listdir(sourceDirectory):
             filename = os.fsdecode(file)
             if filename.endswith(".jpg") or filename.endswith(".png"):
  
                 print(filename)
  
                 img = cv2.imread('Data/images/' + filename)
                 im_grayRef = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
                 for templateFile in os.listdir(templateDirectory):
                     templateFilename = os.fsdecode(templateFile)
  
                     if filename.endswith(".jpg") or filename.endswith(".png"):
                         Sample_image = cv2.imread('Data/Sample_images/' + templateFilename, 0)
                         #im_graySam = cv2.cvtColor(Sample_image, cv2.COLOR_BGR2GRAY)
                         cv2.waitKey(0)
                         w, h = Sample_image.shape[::-1]
  
                         score = cv2.matchTemplate(im_grayRef,Sample_image,cv2.TM_CCOEFF_NORMED)
                         #diff = (diff * 255).astype("uint8")
                         cv2.waitKey(0)
                         diffvalue = print("Image similarity %ge of_" + filename + "_&amp;_" + templateFilename + "_is", score * 100)
                         # res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
                         loc = np.where(score &gt;= threshold)
  
                         if (len(loc[0])):
                             detectedCount = detectedCount + 1
                             for pt in zip(*loc[::-1]):
                                 cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
                         cv2.imwrite(resultsDirectory + '/diff_per_' + filename + '.jpg', img)
                         Difference_per_label.config(text='diff_per ' + filename + "_&amp;_" + templateFilename + ' saved')
                         print('diff_per ' + filename + "_&amp;_" + templateFilename + ' saved')
                             # break
                 #print('detected positive ' + str(detectedCount))
                 continue
             else:
                 continue
  
  
  if __name__ == '__main__':
  
  
     root = tk.Tk()
     root.title('Image GUI')
     root.geometry('1280x960')
     os.makedirs('Data/Differece_images', exist_ok=True)
     pw_left = tk.Frame(root, relief='ridge', borderwidth=4)
     pw_left.pack(side='left',anchor='nw')
     pw_left = tk.Frame(root, relief='ridge', borderwidth=4)
     pw_left.pack(side='left', anchor='nw')
     frame7 = tk.Frame(pw_left, bd=2, relief="ridge")
     frame7.pack()
     difference_button = Difference_Button(root, frame7)
     Difference_per_label = tk.Label(frame7, text='print', width=40, bg='white', height = '5')
     Difference_per_label.pack(fill=tk.X)
     Diff_label = tk.Label(frame7, textvariable= 'diffvalue', width=40, bg='white', height = '5')
     Diff_label.pack(fill=tk.X)
     Difference_button = tk.Button(frame7, text='Difference',
                                   command=lambda: difference_button.on_click_diff_per_button(Difference_per_label))
     Difference_button.pack(side='bottom', padx=5, pady=5)
     root.mainloop()
  </code></pre>
  
  <p><strong>Help Required section:</strong></p>
  
  <ul>
  <li>How to display the below command output in Tkinter <code>diffvalue = print("Image similarity %ge of_" + filename + "_&amp;_" + templateFilename + "_is", score * 100)</code> </li>
  <li>The below command is not displaying all
  the result from starting to end. It is showing only the last
  output. <code>Difference_per_label.config(text='diff_per ' + filename + "_&amp;_" +    templateFilename + ' saved')</code></li>
  <li>Once it is done I want to apply <strong>try except</strong> logic for the statement corrected label i.e currently displaying as  <code>diffvalue = print("Image similarity %ge of_" + filename + "_&amp;_" + templateFilename + "_is", score * 100)</code> &amp; <code>print('diff_per ' + filename + "_&amp;_" + templateFilename + ' saved')</code> so that if nothing is present in the folder it will throw exception command.</li>
  </ul>
  
  <p><strong>Note:</strong> </p>
  
  <ul>
  <li><em>Image similarity %ge of_</em>: Fixed</li>
  <li><em>filename</em>: Variable</li>
  <li><em>_&amp;_</em>: Fixed</li>
  <li><em>templateFilename</em>:Variable</li>
  <li><em>_is</em>:Fixed</li>
  <li><strong>score*100</strong>: Varies according to the difference percentage</li>
  </ul>
  
  <p>Any help would be appreciated. Thanks in advance.</p>
  
  <p>Req: Please close the answer only if all the solutions of <strong>Help Required section:</strong> is resolved.</p>