title: Fastest way to draw a pixel on tkinter
body: <p><strong>Note: You really only need to read the checklist and understand that I want to do this in Tkinter, the rest of the information is for clarification</strong></p>
  
  <p>The complete code is here: <a href="https://gist.github.com/SnugBug/1cc5ea67d11487d69aae8549107372ef" rel="nofollow noreferrer">https://gist.github.com/SnugBug/1cc5ea67d11487d69aae8549107372ef</a></p>
  
  <p>I need to be able to manipulate pixels. The goal is to be able to:</p>
  
  <ul>
  <li><p>Control which pixels are drawn first</p></li>
  <li><p>Change the color and position of each pixel</p></li>
  <li><p>Update everything as a whole, so that if a pixel changes the change shows up</p></li>
  <li><p>Clear everything as a whole</p></li>
  </ul>
  
  <p>The question is, what's the fastest way to check off this list in tkinter? I tried creating an image with PIL, then loading it into tkinter, but I cannot update the image or clear it. The other thing I tried is using tkinter's PhotoImage class, as shown below:</p>
  
  <pre><code>#The function definitions are in the GIST.
  #This snippet should be enough information to understand the problem, however.
  for i in range(0,3600):
      rot = [0,i,0]
      Tx,Ty,Tz,Zm = [0,0,200,200]
      x,y,z = [10,10,10]
      for m,n in itertools.product(range(-50,50,2),range(-50,50,2)):
          x,y,z = rotate([m,n,0],rot)
          img.put("#ffffff", (int(WIDTH/2 + ((x+Tx)*Zm/(z+Tz))), int(HEIGHT/2 - ((y+Ty)*Zm/(z+Tz)))))
      canvas.update()
      img.blank()
  #the confusing math in the `img.put` call is just 3D math
  </code></pre>
  
  <p>This way is extremely slow. The next way I tried is even slower. It's drawing a line like this:
  <code>canvas.create_line(x,y,x+1,y+1, ...)</code>
  Which creates a line of length 1, showing a single pixel. This is excruciatingly slow.</p>
  
  <p>If the separate image method is the fastest, could you include a working snippet in your answer? I cannot figure out the separate image method. I have PIL installed, that's what I was using to attempt it. I lost the python file so I cannot include the code I used to attempt the separate image method.</p>
  
  <p>What I mean by the <em>separate image method</em>: create an image using PIL, drawing on it using PIL, then making that show up on a tkinter screen. This doesn't meet everything on the checklist, however (from what I understand).</p>
  
  <p>If the separate image method is not the fastest, please tell me a way I can check off everything in the checklist some other way. I have a few questions I looked at for help and some sites. They're below</p>
  
  <p><a href="https://stackoverflow.com/questions/10417524/why-is-photoimage-put-slow">Why is Photoimage put slow?</a>
  Any of these answers don't work for me because it only creates squares. I need to be able to make any shape.</p>
  
  <p><a href="https://stackoverflow.com/questions/12284311/python-tkinter-how-to-work-with-pixels">python tkinter: how to work with pixels?</a>
  This answer doesn't work because it's too slow.</p>
  
  <p><a href="https://stackoverflow.com/questions/3913037/how-to-load-bmp-file-into-bitmapimage-class-tkinter-python">How to load .bmp file into BitmapImage class Tkinter python</a> This could be helpful</p>
  
  <p><a href="http://zetcode.com/gui/tkinter/drawing/" rel="nofollow noreferrer">http://zetcode.com/gui/tkinter/drawing/</a> None of these methods work because I cannot manipulate the order each pixel is drawn, and the color of each individual pixel. If you are familiar with 3D terminology, I need this for a Z-Buffer</p>
  
  <p>If there are any confusions or you need something clarified, please tell me below in the comment section. I am open minded, so if you have a deep understanding of my question and have another idea on how to solve it, I would love to hear it.</p>