Dsaa 43
Dsaa 43
71 theTurtle.pendown()
72 theTurtle.pencolor("#000000")
73 theTurtle.fillcolor("#000000")
74 cmd = PenUpCommand()
75 self.graphicsCommands.append(cmd)
76 cmd = GoToCommand(0,0,1,"#000000")
77 self.graphicsCommands.append(cmd)
78 cmd = PenDownCommand()
79 self.graphicsCommands.append(cmd)
80 screen.update()
81 self.graphicsCommands.parse(filename)
82
83 for cmd in self.graphicsCommands:
84 cmd.draw(theTurtle)
85
86 screen.update()
87
88 fileMenu.add_command(label="Load Into...",command=addToFile)
89
90 def saveFile():
91 filename = tkinter.filedialog.asksaveasfilename(title="Save Picture As...")
92 self.graphicsCommands.write(filename)
93
94 fileMenu.add_command(label="Save As...",command=saveFile)
95
96 fileMenu.add_command(label="Exit",command=self.master.quit)
97
98 bar.add_cascade(label="File",menu=fileMenu)
99
100 # This tells the root window to display the newly created menu bar.
101 self.master.config(menu=bar)
102
103 # Here several widgets are created. The canvas is the drawing area on
104 # the left side of the window.
105 canvas = tkinter.Canvas(self,width=600,height=600)
106 canvas.pack(side=tkinter.LEFT)
107
108 # By creating a RawTurtle, we can have the turtle draw on this canvas.
109 # Otherwise, a RawTurtle and a Turtle are exactly the same.
110 theTurtle = turtle.RawTurtle(canvas)
111
112 # This makes the shape of the turtle a circle.
113 theTurtle.shape("circle")
114 screen = theTurtle.getscreen()
115
116 # This causes the application to not update the screen unless
117 # screen.update() is called. This is necessary for the ondrag event
118 # handler below. Without it, the program bombs after dragging the
119 # turtle around for a while.
120 screen.tracer(0)
121
122 # This is the area on the right side of the window where all the
123 # buttons, labels, and entry boxes are located. The pad creates some empty
124 # space around the side. The side puts the sideBar on the right side of the
125 # this frame. The fill tells it to fill in all space available on the right
126 # side.
127 sideBar = tkinter.Frame(self,padx=5,pady=5)
128 sideBar.pack(side=tkinter.RIGHT, fill=tkinter.BOTH)
129
130 # This is a label widget. Packing it puts it at the top of the sidebar.
131 widthLabel = tkinter.Label(sideBar,text="Width")
132 widthLabel.pack()
133
134 # This entry widget allows the user to pick a width for their lines.
135 # With the widthSize variable below you can write widthSize.get() to get
136 # the contents of the entry widget and widthSize.set(val) to set the value
137 # of the entry widget to val. Initially the widthSize is set to 1. str(1) is needed