And which adds a shape represented by the dictionary shape to the tkinter Canvas can. The following fragment of code illustrates the operation of the function:

computer science

Description

 

Exercise 2 (3 marks)

Write and test a function whose first line is

def drawOnCanvas(can, shape):

And which adds a shape represented by the dictionary shape to the tkinter Canvas can. The following fragment of code illustrates the operation of the function:

from tkinter import *

root = Tk()

can = Canvas(root,width = 200, height = 100)

can.pack()

shape1 = {'bounds': [20, 20, 80, 50], 'kind': 'rect', 'fill': True}

shape2 = {'bounds': [80, 50, 20, 35], 'kind': 'tri', 'fill': False}

drawOnCanvas(can, shape1)

drawOnCanvas(can, shape2)

root.mainloop()

Figure 5: Code Fragment Illustrating Use of drawOnCanvas

The code fragment would produce output as shown in Figure 6 below.

Figure 6: Output from Code in Figure 5


Related Questions in computer science category