Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from tkinter import * import random #------------------------------------------- #------------------------------------------- # 1) Make one change to the main() function #------------------------------------------- def main(): size = 10 number_of_rows =

image text in transcribedimage text in transcribedimage text in transcribed

from tkinter import * import random

#------------------------------------------- #------------------------------------------- # 1) Make one change to the main() function #------------------------------------------- def main(): size = 10 number_of_rows = 50 max_in_each_row = 40 min_in_each_row = 25 start_left1 = size * 2 start_down = size * 2

canvas_width = size * max_in_each_row * 2 +size * 5 canvas_height = number_of_rows * size + size * 4 window = Tk() window.title("A5 by mzha263") geometry_string = str(canvas_width)+"x"+str(canvas_height)+"+10+20" window.geometry(geometry_string) a_canvas = Canvas(window)

a_canvas.config(background="blue") a_canvas.pack(fill=BOTH, expand = True) #Canvas fills the whole window

pattern_list = get_list_of_rows(number_of_rows, min_in_each_row, max_in_each_row) #2

longest_string_length = get_length_of_longest(pattern_list) #3 print_pattern_info(pattern_list, longest_string_length, size) #4

draw_pattern_version1(a_canvas, pattern_list, size, start_left1, start_down)#5

start_left2 = start_left1 + size * 3 + longest_string_length * size draw_pattern_version2(a_canvas, pattern_list, size, start_left2, start_down, longest_string_length) #6

window.mainloop() #------------------------------------------- #------------------------------------------- # 2. get_list_of_rows() function #------------------------------------------- def get_list_of_rows(number_of_rows, min_in_each_row, max_in_each_row): possible_digits = "12345" result = []

for i in range(number_of_rows): one = "" l = random.randint(min_in_each_row, max_in_each_row) for j in range(l): one += str(random.randint(1, 5)) result.append(one) return result #------------------------------------------- #------------------------------------------- # 3. get_length_of_longest() function #------------------------------------------- def get_length_of_longest(pattern_list): result = 0 for one in pattern_list: if len(one) > result: result = len(one) return result

#------------------------------------------- #------------------------------------------- # 4. print_pattern_info() function #------------------------------------------- def print_pattern_info(pattern_list, longest_length, size): print("Pattern info:") print("Size:", size, "pixels") print("Number of rows:", str(len(pattern_list))+",", "longest row length:", longest_length) print(" Pattern of digits in each row:") for i in range(len(pattern_list)): print(" ", i+1, "--", pattern_list[i])

#------------------------------------------- #------------------------------------------- # 5. draw_pattern_version1() function #------------------------------------------- def draw_pattern_version1(a_canvas, pattern_list, size, left, top): possible_digits = "12345" colours = ["red", "blue", "green", "yellow", "black"] #------------------------------------------- #------------------------------------------- # 6. draw_pattern_version2() function #------------------------------------------- def draw_pattern_version2(a_canvas, pattern_list, size, left, top, longest_width): possible_digits = "12345" colours = ["red", "blue", "green", "yellow", "black"]

main()

5. draw_pattern_version1(a_canvas, pattern_list, size, left, top) This function is passed five parameters: the Canvas object, a list of string elements, followed by three integer parameters. The function draws a grid of coloured rectangles inside the canvas area. The left-top position of the grid of coloured rectangles is given by the last two parameter values and the size of each rectangle is given by the size parameter. Each element of the pattern_list parameter is a string of digits and each element corresponds to one row of coloured rectangles. Each digit of the string element dictates the colour of the rectangle, e.g., the digit 1 means that the rectangle is filled with red, the digit 2 means that the rectangle is filled with blue, the digit 3 means that the rectangle is filled with green, etc. Note that the first two lines of this function are (you may use any colours of your choice): possible digits "12345" colours["red", "blue", "green", "yellow", "black" Once you have completed this function you should see rows of coloured rectangles (of varying lengths) on the left hand side of the canvas area. . 6. draw_pattern_version2(a_canvas, pattern_list, size, left, top, longest_width) This function is passed six parameters: the Canvas object, a list of string elements, followed by four integer parameters. Inside the canvas area the function draws a mirror image of the grid of coloured rectangles drawn in Part 5. above, i.e., if you were to fold the canvas down the middle line each coloured square lies exactly over a square of the same colour. Note that the first two lines of this function are (use the same colours as you used in Part 6. above): possible digits - "12345 colours- ["red", "blue", "green", "yellow", "black"] Once you have completed this function and you test your program, you should see a mirror image of the Part 5. grid of coloured squares on the right hand side of the Canvas area. The program skeleton: The skeleton of this assignment program is shown below. You need to define five of the function:s and make one small change to the main() function. Rename the file to 'YourUsernameA5-py', e.g., afer023A5.py. 5. draw_pattern_version1(a_canvas, pattern_list, size, left, top) This function is passed five parameters: the Canvas object, a list of string elements, followed by three integer parameters. The function draws a grid of coloured rectangles inside the canvas area. The left-top position of the grid of coloured rectangles is given by the last two parameter values and the size of each rectangle is given by the size parameter. Each element of the pattern_list parameter is a string of digits and each element corresponds to one row of coloured rectangles. Each digit of the string element dictates the colour of the rectangle, e.g., the digit 1 means that the rectangle is filled with red, the digit 2 means that the rectangle is filled with blue, the digit 3 means that the rectangle is filled with green, etc. Note that the first two lines of this function are (you may use any colours of your choice): possible digits "12345" colours["red", "blue", "green", "yellow", "black" Once you have completed this function you should see rows of coloured rectangles (of varying lengths) on the left hand side of the canvas area. . 6. draw_pattern_version2(a_canvas, pattern_list, size, left, top, longest_width) This function is passed six parameters: the Canvas object, a list of string elements, followed by four integer parameters. Inside the canvas area the function draws a mirror image of the grid of coloured rectangles drawn in Part 5. above, i.e., if you were to fold the canvas down the middle line each coloured square lies exactly over a square of the same colour. Note that the first two lines of this function are (use the same colours as you used in Part 6. above): possible digits - "12345 colours- ["red", "blue", "green", "yellow", "black"] Once you have completed this function and you test your program, you should see a mirror image of the Part 5. grid of coloured squares on the right hand side of the Canvas area. The program skeleton: The skeleton of this assignment program is shown below. You need to define five of the function:s and make one small change to the main() function. Rename the file to 'YourUsernameA5-py', e.g., afer023A5.py

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago

Question

Be prepared to address excessive absenteeism

Answered: 1 week ago