title: Several questions on Tkinter - mainloop, update method, effectiveness etc
body: <p>Background: I'm trying to write a graphics library for python built on top of Tkinter. I therefore would like to abstract all of Tkinter's functionality from the user and have method calls that modify the root window sequentially in a Processing-like manner. e.g my library (let's call it mylib) would enable you to write code like this:</p>
  
  <pre><code>from mylib import * #this would be my library
  window(400, 400) #open a new window to add objects to
  color('red') #set the color of all subsequent items to red
  circle(radius=5, centerx = 0, centery=0) #make a red circle
  line(10,10, 20, 20) #red line going from (10, 10) to (20, 20)
  color('blue')
  line(50, 50, 100, 100) #blue line
  </code></pre>
  
  <p>I thought of implementing it like this:</p>
  
  <pre><code>try:
      from tkinter import *
  except:
      from Tkinter import *
  
  _root = Tk()
  
  
  class MyCanvas(Canvas):
      def __init__(self, width=400, height=400):
          master = Toplevel(_root)
          Canvas.__init__(self, master, width=width, height=height)
          self.pack()
          self.items = []
          self.width = width
          self.height = height
          _root.mainloop()
  
  
  global _c
  _c = None
  
  def window():
      _c = MyCanvas()
      _c.pack()
  
  def line(a,b,c,d):
      #config code goes here
      _c.create_line(a,b,c,d)
  
  #test
  window()
  line(10, 10, 50, 50)
  </code></pre>
  
  <p>That didn't work because Python wouldn't get out of mainloop() so I tried this instead:
      try:
          from tkinter import *
      except:
          from Tkinter import *</p>
  
  <pre><code>_root = Tk()
  
  
  class MyCanvas(Canvas):
      def __init__(self, width=400, height=400):
          master = Toplevel(_root)
          Canvas.__init__(self, master, width=width, height=height)
          self.pack()
          self.items = []
          self.width = width
          self.height = height
  
  
  
  global _c
  _c = None
  
  def window():
      _c = MyCanvas()
      _c.pack()
  
  def line(a,b,c,d):
      #config code goes here
      _c.create_line(a,b,c,d)
      _root.update_idletasks()
  
  #test
  window()
  line(10, 10, 50, 50)
  </code></pre>
  
  <p>But that didn't work too - it just froze. And I tried replacing update_idletasks with update. The window froze again. How do I use update properly?</p>
  
  <p>Is there a way to accomplish this using mainloop() without having the user explicitly call it?</p>
  
  <p>Or is there a way to edit widgets in mainloop? I thought about using after but I didn't see how that would solve the problem.</p>
  
  <p>If no answer exits given these constraints would writing the package in PyOpenGL be useful or portable ? Should I write the module using C from scratch? Does anything else exist? Help me!!!</p>
  
  <p>Sorry for the long question. I've been at this for hours now to no avail.</p>