title: How to save image data from clipboard to a file in Python 3 on Debian, using tkinter?
body: <p>I'm trying to use the <code>tkinter</code> solution for obtaining clipboard image data copied from GIMP, but cannot make it work, saving the data to file:</p>
  
  <pre><code>from tkinter import Tk
  r = Tk()
  r.withdraw()
  clip = r.clipboard_get(type="image/png")
  r.update()
  r.destroy()
  with open("testbytes.png", mode="bw+") as f:
      f.write(clip.encode())
  </code></pre>
  
  <p>When I try to open the testbytes.png file, the Image Viewer reports a fatal error, not a PNG file. I obtained the <code>type</code> parameter for the <code>clipboard_get()</code> call with <code>r.selection_get(selection='CLIPBOARD', type='TARGETS')</code>, which returned:</p>
  
  <pre><code>'TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS image/png image/bmp image/x-bmp image/x-MS-bmp image/x-icon image/x-ico image/x-win-bitmap image/vnd.microsoft.icon application/ico image/ico image/icon text/ico image/tiff image/jpeg '
  </code></pre>
  
  <p>I think the format of the data on the clipboard is PNG. I've also tried JPEG, BMP and TIFF, but they result in similar errors.</p>
  
  <p>What am I doing wrong?</p>