title: How to use cv2.videowriter to record the computer screen with the use of Tkinter and without displaying the screen while recording it (imgshow)
body: <p>What in reality I want to do is:</p>
  <ol>
  <li><p>To use Tkinter buttons to:</p>
  <p>1.1. Start recording the screen</p>
  <p>1.2. Stop recording the screen</p>
  </li>
  <li><p>Not to display the video that is being recorded simultaneously during the recording.</p>
  </li>
  </ol>
  <p>Here is my code:</p>
  <pre><code>import tkinter as tk
  import cv2
  import numpy as np
  from PIL import ImageGrab
  
  window = tk.Tk()
  window.title('ScreenVideo')
  window.geometry('350x300')
  
  #ScreenVideo
  
  def StartS():
      fourcc = cv2.VideoWriter_fourcc(*'XVID')
      vid=cv2.VideoWriter(&quot;c:\\IQOutput\\rec.avi&quot;, fourcc, 10, (990,690))
  
      while(True):
          img = ImageGrab.grab(bbox=(10,10,1000,700))
          img_np=np.array(img)
          frame=cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
          vid.write(frame)
          cv2.imshow(&quot;frame&quot;, frame)
          key=cv2.waitKey(1)
          if key==27:
              break
  
      vid.release()
      cv2.destroyAllWindows()
  
  bstarts = tk.Button(window, text='StartRe', font=('Arial', 8), bg='light pink', width=5, height=1, command=StartS)     
  bstarts.place(x=280, y=80, anchor='nw')
  
  bstops = tk.Button(window, text='StopRe', font=('Arial', 8), bg='light pink', width=5, height=1, command=StopRe)     
  bstops.place(x=280, y=120, anchor='nw')
  </code></pre>
  <p>The piece of code above has the options below:</p>
  <p>(a). Starts recording when the user clicks the Bstarts button.</p>
  <p>(b). Shows the screen simultaneously while recording it within a &quot;frame&quot; window.</p>
  <p>(c). Stops recording when the user presses the &quot;esc&quot; key on PC.</p>
  <p>(d). Saves the final video (named: &quot;rec.avi&quot;) in the path <code>C:\IQOutput\</code>.</p>
  <p>But the options I expect this program to have are:</p>
  <p>(a). When the user clicks the Bstarts button, it starts to record the screen (that is already working).</p>
  <p>(b). Not to show the screen simultaneously while recording on the screen (how can I remove or hide the function related to &quot;imshow&quot; while the screen is being recorded?)</p>
  <p>(c). When the user clicks the Bstops button, it stops recording the screen.</p>
  <p>(d). It saves the final video named &quot;rec.avi&quot; in the path <code>c:\IQOutput\</code>.</p>