title: How do I save an image in python 3 using PIL?
body: <p>I am using PIL in python 3 in a program that recolours an image. What it does is, it permanently loops through the pixel values of <code>file.gif</code> (which are returned as integers) and then adds 10 to each of them. I then want it to save the file, which can then be reopened to write to a tkinter label (I've got the rest, but I just need to know about the saving).</p>
  
  <p>Using this code, I have got the program to open the image and display it in the window, then modify the pixel values, but it doesn't change the image displayed.</p>
  
  <pre><code>from tkinter import *
  from PIL import Image
  from PIL import Image, ImageTk
  import time, sys
  
  def col():
      global count1,count,pix,x,root
      count1+=1
      print("("+str(count1)+")")
      count=-1
      for i in pix:
          count+=1
          #print(i)
          i+=10
          pix[count]=i
  
      photo = PhotoImage(file="AI.gif")
      x.configure(image=photo)
      root.update()
      root.after(100, col)
  
  root=Tk()
  
  photo = PhotoImage(file="AI.gif")
  x=Label(root, compound="top", image=photo)
  x.pack(side="right")
  
  img = Image.open("AI.gif")
  pix=list(img.getdata())
  width=img.size[0]
  height=img.size[1]
  img.close()
  
  root.geometry((str(width)+"x"+str(height))+"-0+0")
  root.update()
  
  count1=0
  col()
  
  root.mainloop()
  </code></pre>
  
  <p>I am using this image currently:
  <a href="https://i.stack.imgur.com/xFn93.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xFn93.gif" alt="enter image description here"></a></p>
  
  <p><strong>Edit:</strong>
  @Tadhg McDonald-Jensen
  I've just run the program with all your suggested edits, but have got this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\name\Desktop\recolour1.py", line 47, in &lt;module&gt;
      col()
    File "C:\Users\name\Desktop\recolour1.py", line 19, in col
      photo.paste(img)
  AttributeError: 'PhotoImage' object has no attribute 'paste'
  </code></pre>
  
  <p><strong>Edit2:</strong>
  here is my latest version of the code that doesn't seem to be modifying the image in the tkinter window:</p>
  
  <pre><code>from tkinter import *
  from PIL import Image
  from PIL import Image, ImageTk
  import time, sys
  
  def col():
      global count1,count,pix,x,root,photo
      img = Image.open("AI.gif").convert("RGB")
      pix=list(img.getdata())
      count1+=1
      print("("+str(count1)+")")
      count=-1
      for i in pix:
          count+=1
          #print(i)
          i = tuple(V+100 for V in i)
  
      img.putdata(pix)
      photo.paste(img)
      root.update()
      img.close()
      root.after(10, col)
  
  root=Tk()
  photo = ImageTk.PhotoImage(file="AI.gif")
  x=Label(root, compound="top", image=photo)
  x.pack(side="right")
  img = Image.open("AI.gif").convert("RGB")
  width,height=img.size[0],img.size[1]
  img.close()
  root.geometry((str(width)+"x"+str(height))+"-0+0")
  root.update()
  count1=0
  col()
  root.mainloop()
  </code></pre>