# we need a root window object and then a Canvas window object (child) # in order to be able to draw points and lines. # The Point and Line draw() method will use this canvas. # # A Canvas Window on which we can draw points, lines, rectangles, etc. # See the Tkinter module, Canvas class, for more details. # PyScripter may not handle Tkinter well, so to run this example, # use the command line: # python prog.py from xcanvas import * try: rootWindow except NameError: rootWindow = Tkinter.Tk() # This is where we create our canvas instance # The name canvas referes to it when you import this module canvas = XCanvas(rootWindow, width=1000, height=800, bg="white") colors = 10 * ['red1', 'DarkGoldenrod2', 'yellow2', 'DarkOliveGreen1', 'chartreuse1', 'green3', 'DarkSlateGray3', 'MediumPurple3', 'MediumOrchid4', 'MediumOrchid3', 'thistle2', 'gray'] color_index = -1 def show_graphics(): Tkinter.mainloop() def get_next_color(): global color_index global colors color_index += 1 if color_index >= len(colors): color_index = 0 return colors[color_index] #----------------------------------------------------------------------- def test1(): id = canvas.create_rectangle(100, 120, 400, 230, width=2, outline='blue', fill='yellow') id = canvas.create_rectangle(400, 320, 600, 530, width=2, outline='blue', fill='yellow') id = canvas.create_line(200, 50, 500, 430, width=3, fill='blue') #print canvas['scrollregion'] canvas.show() show_graphics() def test2(): # Hide the main canvas canvas.hide() # We can actually create multiple canvas instances ! rootwin1 = Tkinter.Tk() canvas1 = XCanvas(rootwin1, width=1000, height=800, bg="white") canvas1.create_rectangle(100, 120, 400, 230, width=2, outline='blue', fill='yellow') canvas1.create_rectangle(400, 320, 600, 530, width=2, outline='blue', fill='yellow') canvas1.create_line(200, 50, 500, 430, width=3, fill='blue') #print canvas1['scrollregion'] rootwin2 = Tkinter.Tk() canvas2 = XCanvas(rootwin2, width=1000, height=800, bg="gray90") canvas2.create_rectangle(100, 120, 400, 230, width=2, outline='red', fill='yellow') canvas2.create_rectangle(400, 320, 600, 530, width=2, outline='red', fill='yellow') canvas2.create_line(200, 50, 500, 430, width=3, fill='red') #canvas1.show() #canvas2.show() show_graphics() if __name__ == "__main__": #test1() test2()