title: Saving canvas from tkinter to file
body: <p>So I followed this post:
  <a href="https://stackoverflow.com/questions/9886274/how-can-i-convert-canvas-content-to-an-image">How can I convert canvas content to an image?</a></p>
  
  <p>And when I tried to do as mentioned in the last suggestion, I get the following problem:</p>
  
  <p>When I call it out like this, the image/screenshot is taken too early and therefore the required image won't be captured. Here's the code:</p>
  
  <pre><code>from tkinter import *
  from PIL import ImageGrab
  root = Tk()
  cv = Canvas(root)
  
  cv.pack()
  
  cv.create_rectangle(10,10,50,50)
  #cv.create_line([0, 10, 10, 10], fill='green')
  
  
  cv.update()
  
  
  #print(root.winfo_width())
  
  def getter(widget):
      x=root.winfo_rootx()+widget.winfo_x()
      print(x)
      y=root.winfo_rooty()+widget.winfo_y()
      print(y)
      x1=x+widget.winfo_width()
      print(x1)
      y1=y+widget.winfo_height()
      print(y1)
      ImageGrab.grab().crop((x,y,x1,y1)).save("em.jpg")
  
  getter(cv)
  root.mainloop()
  </code></pre>
  
  <p>By the way, if there is a simplier solution, I would appreciate it!
  The thing is that the saving part will be added to the code dynamically later so the solution should be as light as possible.</p>
  
  <p>Thanks in advance!</p>
  
  <p>PS: Maybe it is even possible to save the canvas without displaying it beforehand? Just by the code?</p>