from Tkinter import * import sys #class of the geometric figures. Base is the frame it's called in class base(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() self.Makebase() def Makebase(self): panel(self).pack(side=LEFT) easel(self).pack(side=RIGHT) class panel(Frame): def __init__(self, parent=Frame, **config): Frame.__init__(self, parent, config) self.MyCanvas = Canvas() self.MyEasel = easel(self.MyCanvas) self.pack(side = TOP, fill = BOTH) self.MakeGUI() def MakeGUI(self): Circle = Button (self,text = "Circle") #creates the button on the root frame Circle.pack(side = TOP,fill = X, anchor = N) #'packs' the button, putting it on the frame and specifying resizing options Circle.bind('', self.bringUpCircle) #registers mouse event and sends it to the circle() function Square = Button (self, text = "Square") Square.pack(side = TOP, fill = X, anchor = N) Square.bind('', self.bringUpSquare) Triangle = Button (self, text = "Triangle") Triangle.pack(side = TOP, fill = X, anchor = N) Triangle.bind('', self.bringUpTriangle) Color = Button (self, text = "Color") Color.pack(side = TOP, fill = X, anchor = N) Color.bind('', self.bringUpColor) Rotate = Button (self, text = "Rotate") Rotate.pack(side = TOP, fill = X, anchor = N) Rotate.bind('', self.bringUpRotate) Erase = Button (self, text = "Erase") Erase.pack(side = TOP, fill = X, anchor = N) Erase.bind('', self.bringUpErase) Pen = Button (self, text = "Pen") Pen.pack(side = TOP, fill = X, anchor = N) Pen.bind('', self.bringUpPen) def bringUpCircle(self, event): self.circle(event) def bringUpSquare(event): self.square(event) def bringUpTriangle(event): self.triangle(event) def bringUpColor(event): self.cplor(event) def bringUpRotate(event): self.rotate(event) def bringUpErase(event): self.erase(event) def bringUpPen(event): self.pen(event) def circle(self, event): self.MyEasel.DrawCircle(self.MyCanvas, event) def square(event): print "eventually I'll draw a square but for now I just quit" import sys; sys.exit() #kills windows def triangle(event): print "eventually I'll draw a triangle but for now I just quit" import sys; sys.exit() #kills windows def color(event): print "eventually I'll change colors but for now I just quit" import sys; sys.exit() #kills windows def rotate(event): print "eventually I'll rotate objects but for now I just quit" import sys; sys.exit() #kills windows def erase(event): print "eventually I'll erase but for now I just quit" import sys; sys.exit() #kills windows def pen(event): print "eventually I'll draw with a pen but for now I just quit" import sys; sys.exit() #kills windows class easel(Canvas): def __init__(self, parent=Frame, **config): Canvas.__init__(self, parent, config) self.pack(side = TOP, fill = BOTH, expand = YES) self.Makeeasel() def Makeeasel(self): MyCanvas = Canvas(self, width = 500, height=200, bg = 'white') MyCanvas.config(scrollregion =(0,0,500,2000)) #start of scrollbar code sbar = Scrollbar(self) sbar.config(command = MyCanvas.yview) MyCanvas.config(yscrollcommand=sbar.set) sbar.pack(side = RIGHT, fill=Y) #end of scrollbar code MyCanvas.pack(side = RIGHT, expand = YES, fill = BOTH) def DrawCircle(self, MyCanvas, event): MyCanvas.create_oval(100,100,20,20,width=2,fill="pink") print "you've almost got it!" def DrawSquare(self, Mycanvas): Mycanvas.create_line(100,100,20,0, width=2) Mycanvas.create_line(120,100,0,-20,width=2) Mycanvas.create_line(120,120,-20,0,width=2) Mycanvas.create_line(100,120,0,-20,width=2) def DrawTriangle(self, Mycanvas): Mycanvas.create_oval(100,100,20,20,width=2,fill="blue") def DrawColor(self, Mycanvas): Mycanvas.create_oval(100,100,20,20,width=2,fill="blue") def DrawRotate(self, Mycanvas): Mycanvas.create_oval(100,100,20,20,width=2,fill="blue") def DrawErase(self, Mycanvas): Mycanvas.create_oval(100,100,20,20,width=2,fill="blue") def DrawPen(self, Mycanvas): Mycanvas.create_oval(100,100,20,20,width=2,fill="blue") if __name__ == '__main__': base().mainloop()