title: Python code activated with checkbox/button
body: <p>I want to call function doit when Checkbutton is ON and stop it when it's OFF. </p>
  
  <p>I tried to do it with button and it kinda works, but when I have my CheckButton in ON and I click my button my window freeze and I can't turn it off again.</p>
  
  <pre><code>from tkinter import *
  import PIL.ImageGrab
  from PIL import ImageGrab
  import time
  import cv2
  import numpy as np
  import pyautogui
  import random
  
  
  def doit():
      time.clock()
      while label_text.get()=="ON":
          rgb = PIL.ImageGrab.grab().load()[1857,307]
          print(rgb)
          print(time.clock())
      else:
          print('module is turned OFF')
  
  window = Tk()
  
  label_text = StringVar()
  label = Label(window, textvariable=label_text)
  label_text.set("OFF")
  
  check=Checkbutton(window,  text=label_text.get(), variable=label_text,
                     onvalue="ON", offvalue="OFF")
  
  label.pack()
  check.pack(side="left")
  
  b = Button(window, text="OK", command=doit)
  b.pack()
  
  window.mainloop()
  </code></pre>