title: Can't manage to get correct area selection for ImageGrab.grab() even when copying online code that is supposed to work. Multiple exemples tried
body: <p>Fixed: Solution at the end.</p>
  <p>I am trying to export/save a tkinter canvas by using the ImageGrab.grab() method.
  However the saved image is always off by a bunch of pixels.
  I tried many exemples as well as my own tries.</p>
  <p>Question:
  Can you try to run this code and tell me if you get the whole visible canvas saved (make sure to change the uploaded image (line 17).
  How can I save the whole visible canva?</p>
  <p>Here is a code exemple that you can try (note that here I tried the crop method).
  At the end of it you can see multiple exemples that I have tried.</p>
  <pre><code>from tkinter import *
  from PIL import ImageTk, Image
  import tkinter as tk
  import pyscreenshot as ImageGrab   
  
  def exportCanvas(event=1):  #try whatever you want here
      print(&quot;exporting....&quot;)  #to know that the function has started
      ImageGrab.grab().crop((canvas.winfo_rootx(), canvas.winfo_rooty() ,canvas.winfo_rootx()+canvas.winfo_width(), canvas.winfo_rooty()+canvas.winfo_height())).save(&quot;testImageGrab.png&quot;)
      print(&quot;... export ended.&quot;)  #to know that the function has finished
  
  #Create root and canvas
  root = tk.Tk()
  canvas = tk.Canvas(root, width=400, height=400, background=&quot;bisque&quot;)
  canvas.pack(fill=BOTH, expand=1)
  
  #Plot an image          !!!!! Change text.png&quot; to an image you have in your repertory !!!!!
  imageTemp=Image.open(&quot;text.png&quot;)
  schematicImage=ImageTk.PhotoImage(imageTemp)
  imageAffichee=canvas.create_image(0,0,image=schematicImage)
  
  #Bind q key to start the exporting/saving of the canvas
  root.bind(&quot;&lt;Key-q&gt;&quot;,exportCanvas)
  
  root.mainloop()
  
  
  &quot;&quot;&quot;
  Things that I have tried but doesn't get the right part of the screen
  
  1: f.leno (https://stackoverflow.com/questions/47653748/performing-imagegrab-on-tkinter-screen)
  
  box = (canvas.winfo_rootx(),canvas.winfo_rooty(),canvas.winfo_rootx()+canvas.winfo_width(),canvas.winfo_rooty() + canvas.winfo_height())
  grab = ImageGrab.grab(bbox = box)
  grab.save(&quot;testImageGrab.png&quot;)
  
  2: B.Jenkins (https://stackoverflow.com/questions/9886274/how-can-i-convert-canvas-content-to-an-image)
  
  x=root.winfo_rootx()+canvas.winfo_x()
  y=root.winfo_rooty()+canvas.winfo_y()
  x1=x+canvas.winfo_width()
  y1=y+canvas.winfo_height()
  ImageGrab.grab().crop((x,y,x1,y1)).save(&quot;testImageGrab.png&quot;)
  
  3: Alon (https://stackoverflow.com/questions/9886274/how-can-i-convert-canvas-content-to-an-image)
  
  ImageGrab.grab(bbox=(
  canvas.winfo_rootx(),
  canvas.winfo_rooty(),
  canvas.winfo_rootx() + canvas.winfo_width(),
  canvas.winfo_rooty() + canvas.winfo_height()
  )).save(&quot;testImageGrab.png&quot;)
  
  4: Mike - SMT (https://stackoverflow.com/questions/54637592/how-to-screenshot-the-entire-tkinter-canvas-as-png-or-pdf)
  
  x = root.winfo_rootx() + canvas.winfo_x()
  y = root.winfo_rooty() + canvas.winfo_y()
  xx = x + canvas.winfo_width()
  yy = y + canvas.winfo_height()
  ImageGrab.grab(bbox=(x, y, xx, yy)).save(&quot;testImageGrab.png&quot;)
  &quot;&quot;&quot;
  </code></pre>
  <p>This code is expected to get the whole visible canvas saved, however this is what I get:
  <a href="https://i.stack.imgur.com/wfemz.png" rel="nofollow noreferrer">Result</a></p>
  <p>This is my whole screen:<a href="https://i.stack.imgur.com/vzSUz.jpg" rel="nofollow noreferrer">WholeScreen</a></p>
  <p>Additionnaly I made this program that should save the selected area of the canva.
  It works by saving the whole screen (this is working, I tried it individually) then cropping by selection. The event.x and event.y should return the x and y value of the mouse position on the screen, not on the canva which is waht we are looking for when cropping a screen shoot of the whole screen.</p>
  <pre><code>from tkinter import *
  from PIL import ImageTk, Image
  import tkinter as tk
  import pyscreenshot as ImageGrab   
  
  def qPressed(event=1):
      global started
      started = 1
      #change cursor style so that we know we are about to start the area selection
      root.config(cursor=&quot;cross&quot;)
  
  def B1Motion (event=1):
      global started, initPos, x, y
      if started:
          if (initPos==0):
              #get the initial values (x and y pos of the first mouse 1 click)
              x=event.x
              y=event.y
              initPos=1
  
  def B1Release (event=1):
      global started, initPos, x, y
      if started:
          if initPos:
              #to know that the function has started
              print(&quot;exporting....&quot;)  #to know that the function has started
              #grab screen, crop based on x and y of first time mouse 1 was pressed after q was pressed and current x and y of mouse
              ImageGrab.grab().crop((x, y, event.x, event.y)).save(&quot;testImageGrab.png&quot;)   
              #to know that the function has finished
              print(&quot;... export ended.&quot;)  
              #reset the variables and others
              x=0
              y=0
              initPos=0
              started=0
              root.config(cursor=&quot;arrow&quot;)
  
  #Create root and canvas
  root = tk.Tk()
  canvas = tk.Canvas(root, width=400, height=400, background=&quot;bisque&quot;)
  canvas.pack(fill=BOTH, expand=1)
  
  #Variables
  started=0
  initPos=0
  
  #Plot an image          !!!!! Change text.png&quot; to an image you have in your repertory !!!!!
  imageTemp=Image.open(&quot;text.png&quot;)
  schematicImage=ImageTk.PhotoImage(imageTemp)
  imageAffichee=canvas.create_image(0,0,image=schematicImage)
  
  #Binds
  root.bind(&quot;&lt;Key-q&gt;&quot;,qPressed)
  root.bind(&quot;&lt;B1-Motion&gt;&quot;,B1Motion)
  root.bind(&quot;&lt;ButtonRelease-1&gt;&quot;,B1Release)
  
  root.mainloop()
  </code></pre>
  <p>Thank you in advance for your kind answers. &lt;3</p>
  <p>As stated by H3coder, my settings had &quot;application zoom&quot; at 150%. I have been able to fix my issue by simply multiplying my values by 1.5 It would be nice to fetch the &quot;application zoom&quot; value directly from the computer, I ll look into that later.
  So this code works if you don't have a random zoom.</p>