0% found this document useful (0 votes)
16 views1 page

30 1 Python Programming 101: This Copy Belongs To 'Acha04'

Uploaded by

s39769748
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

30 1 Python Programming 101: This Copy Belongs To 'Acha04'

Uploaded by

s39769748
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

30 1 Python Programming 101

197 widthEntry.pack()
198 widthSize.set(str(1))
199
200 radiusLabel = tkinter.Label(sideBar,text="Radius")
201 radiusLabel.pack()
202 radiusSize = tkinter.StringVar()
203 radiusEntry = tkinter.Entry(sideBar,textvariable=radiusSize)
204 radiusSize.set(str(10))
205 radiusEntry.pack()
206
207 # A button widget calls an event handler when it is pressed. The circleHandler
208 # function below is the event handler when the Draw Circle button is pressed.
209 def circleHandler():
210 # When drawing, a command is created and then the command is drawn by calling
211 # the draw method. Adding the command to the graphicsCommands sequence means the
212 # application will remember the picture.
213 cmd = CircleCommand(float(radiusSize.get()), float(widthSize.get()), penColor.get())
214 cmd.draw(theTurtle)
215 self.graphicsCommands.append(cmd)
216
217 # These two lines are needed to update the screen and to put the focus back
218 # in the drawing canvas. This is necessary because when pressing "u" to undo,
219 # the screen must have focus to receive the key press.
220 screen.update()
221 screen.listen()
222
223 # This creates the button widget in the sideBar. The fill=tkinter.BOTH causes the button
224 # to expand to fill the entire width of the sideBar.
225 circleButton = tkinter.Button(sideBar, text = "Draw Circle", command=circleHandler)
226 circleButton.pack(fill=tkinter.BOTH)
227
228 # The color mode 255 below allows colors to be specified in RGB form (i.e. Red/
229 # Green/Blue). The mode allows the Red value to be set by a two digit hexadecimal
230 # number ranging from 00-FF. The same applies for Blue and Green values. The
231 # color choosers below return a string representing the selected color and a slice
232 # is taken to extract the #RRGGBB hexadecimal string that the color choosers return.
233 screen.colormode(255)
234 penLabel = tkinter.Label(sideBar,text="Pen Color")
235 penLabel.pack()
236 penColor = tkinter.StringVar()
237 penEntry = tkinter.Entry(sideBar,textvariable=penColor)
238 penEntry.pack()
239 # This is the color black.
240 penColor.set("#000000")
241
242 def getPenColor():
243 color = tkinter.colorchooser.askcolor()
244 if color != None:
245 penColor.set(str(color)[-9:-2])
246
247 penColorButton = tkinter.Button(sideBar, text = "Pick Pen Color", command=getPenColor)
248 penColorButton.pack(fill=tkinter.BOTH)
249
250 fillLabel = tkinter.Label(sideBar,text="Fill Color")
251 fillLabel.pack()
252 fillColor = tkinter.StringVar()
253 fillEntry = tkinter.Entry(sideBar,textvariable=fillColor)
254 fillEntry.pack()
255 fillColor.set("#000000")
256
257 def getFillColor():
258 color = tkinter.colorchooser.askcolor()
259 if color != None:
260 fillColor.set(str(color)[-9:-2])
261
262 fillColorButton = \
263 tkinter.Button(sideBar, text = "Pick Fill Color", command=getFillColor)
264 fillColorButton.pack(fill=tkinter.BOTH)
265

This copy belongs to 'acha04'

You might also like