title: How to save grabbed image to user-input directory in Python
body: <p>I have worked at this code:</p>
  
  <pre><code>def getnsave(event):
      widget=event.widget
      x=root.winfo_rootx()+widget.winfo_x()
      y=root.winfo_rooty()+widget.winfo_y()
      x1=x+widget.winfo_width()
      y1=y+widget.winfo_height()
      formats=[('Obrázky (.png)','*.png'),('Obrázky (.jpg)','*.jpg')]
      img=ImageGrab.grab().crop((x,y,x1,y1))
      f=filedialog.asksaveasfile(filetypes=(("Portable Network Graphics (*.png)", "*.png"),("All Files (*.*)", "*.*")),mode='w',defaultextension='.png')
      if f is None:
          return
      f.write(img)
      f.close()
  </code></pre>
  
  <p>and I'm getting this error:</p>
  
  <pre><code>TypeError: write() argument must be str, not Image
  </code></pre>
  
  <p>Please, help me. I understand, that after I select the directory, I need to command WHAT to save. Do You know how to do it?</p>