title: Tkinter GUI freezes while running looping
body: <p>I'm new to python coding and I have been working on a project which could click on an image based on a chosen color. I have been using a program which loops the search 50 times when I click the start button. However, I have been trying to implement a stop button, but the problem is that my code freezes when the loop is running. Any ideas?</p>
  
  <p>I have heard to try threading but it seems very complicated and I have been unable to follow any tutorials properly in relation to my code. By the way, the image searched has been testing images I've been using stored inside the program files.</p>
  
  <pre><code>from imagesearch import *
  import pyautogui
  import tkinter as tk
  from tkinter import *
  from tkinter.ttk import *
  import time
  import threading
  
  
  # ---Defined Programs---
  def run():
      global enterColor
      enterColor = str(enterColorField.get())
      program(enterColor)
  
  
  def program(color):
      whitePos = imagesearch_numLoop(str(color) + ".PNG", 0, 50)
      pyautogui.moveTo(whitePos[0] + 20, whitePos[1] + 10)
      pyautogui.click()
  
  
  def stop():
      print("Placeholder")
  
  
  # ---Main Runner---
  window = tk.Tk()
  window.geometry("250x250")
  window.configure(background="#181b54")
  
  app = tk.Frame(window)
  app.grid()
  
  enterColorLabel = tk.Label(window, text="Enter Color:", bg="#181b54", fg="white")
  enterColorLabel.place(x=10, y=50)
  
  enterColorField = Combobox(window)
  enterColorField['values'] = ("Black", "White")
  enterColorField.current("0")  # set the selected item
  enterColorField.place(x=10, y=70)
  
  submitButton = tk.Button(window, text="Start", bg="#66ff00", command=run)
  submitButton.place(x=10, y=130)
  
  stopButton = tk.Button(window, text="Stop", bg="red", command=stop)
  stopButton.place(x=50, y=130)
  
  window.mainloop()
  
  
  #---New Python Script---
  import cv2
  import numpy as np
  import pyautogui
  import random
  import time
  
  def imagesearch_numLoop(image, timesample, maxSamples, precision=0.8):
      pos = imagesearch(image, precision)
      count = 0
      while pos[0] == -1:
          print(image+" not found, waiting")
          count = count + 1
          if count&gt;maxSamples:
              break
          pos = imagesearch(image, precision)
      return pos
  </code></pre>
  
  <p>Whenever clicking start, the whole code freezes. I can't even (x) out.</p>