Question

In: Computer Science

In Python, gonna need this ASAP: Complete the draw_pattern(a_canvas, colours_dictionary, pattern_list, size, left, top) function. This...

In Python, gonna need this ASAP: Complete the draw_pattern(a_canvas, colours_dictionary, pattern_list, size, left, top) function. This function is passed SIX parameters: the Canvas object, a colours dictionary, a list of String elements, and 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. Once you have completed this function you should see rows of coloured rectangles in the canvas area.

def draw_pattern(a_canvas, colours_dictionary, pattern_list, size, left, top):   
down = top

Solutions

Expert Solution

Function:

#Implementation of draw_pattern method

def draw_pattern(a_canvas, colours_dictionary, pattern_list, size,left, top):

    #Iterate the loop

    for pattern in pattern_list:

        #assign pattern[0] to strValue

        strValue = pattern[0]

        #store the value in requiredcolor

        requiredcolor = colours_dictionary[strValue]

        #assign left to direction

        direction = left

        #assign pattern[1] to intValue

        intValue = pattern[1]

        #Iterate the loop

        for each in range(intValue):

            #call rectangle method through canavas a_canvas

            a_canvas.create_rectangle(direction, top, direction + size, top + size, fill=requiredcolor)

            #calculate direction

            direction = direction + size

        #calcualte top

        top = top + size

Code Image:

Sample Output:

Code to Copy:

from tkinter import *

import random

#Implementation of draw_pattern method

def draw_pattern(a_canvas, colours_dictionary, pattern_list, size,left, top):

    #Iterate the loop

    for pattern in pattern_list:

        #assign pattern[0] to strValue

        strValue = pattern[0]

        #store the value in requiredcolor

        requiredcolor = colours_dictionary[strValue]

        #assign left to direction

        direction = left

        #assign pattern[1] to intValue

        intValue = pattern[1]

        #Iterate the loop

        for each in range(intValue):

            #call rectangle method through canavas a_canvas

            a_canvas.create_rectangle(direction, top, direction + size, top + size, fill=requiredcolor)

            #calculate direction

            direction = direction + size

        #calcualte top

        top = top + size

#Implementation of main function

def main():

    #Declare size and initlaize with 10

    size=10

    #assign 2*size to left

    left = 2*size

    top = 2*size

    #Declare pattern_list

    pattern_list = [('4', 3), ('1', 10), ('2', 10), ('3', 10), ('4', 3)]

    #Declare colours_dictionary as dictionary

    colours_dictionary = {"1": "red", "2": "blue", "3": "green", "4": "yellow"}

   #calculate length of pattern_list and assign to number_of_rows

    number_of_rows = len(pattern_list)

    #calculate length of pattern_list[0] and assign to number_of_columns

    number_of_columns = len(pattern_list[0])

    #calculate canvas_width

    canvas_width = size*number_of_columns + size*4

    #calcualte canvas_height

    canvas_height = number_of_rows*size + size*4

    #call Tk()

    userInterface = Tk()

    stringGeometr = str(canvas_width) + "x" +str(canvas_height)+"+10+20"

    #call geometry method

    userInterface.geometry(stringGeometr)

    a_canvas = Canvas(userInterface)

    #set the background color as white for canvas

    a_canvas.config(background="white")

    #call pack method through canvas a_canvas

  a_canvas.pack(fill='both', expand=True)

    #call draw_pattern method

    draw_pattern(a_canvas,colours_dictionary,pattern_list,size,left,top)

    #call mainloop method

    userInterface.mainloop()

   

#call main method

main()

***********************************************************************************************************************************

In case of any doubt do ask in the comment section


Related Solutions

Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): returns [(5, [('Top', ['Yasuo'])]), (4, [('Mid', ['Fiora']), ('Support',['Olaf']), ('Jungle',['Shaco'])])   (3, [('Bottom', ['Fiora']), ('Top', ['Olaf'])]), (2, [('Mid', ['Olaf','Yasuo']), ('Top', ['Shaco'])]), (1, [('Mid', ['Shaco'])])]
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user...
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user for the number of elements, not to exceed arraySize = 20 (put appropriate input validation) Ask the user for the type of data they will enter - EnglishGrade or MathGrade objects. Use your EnglishGrade and MathGrade classes Based on the input, create an appropriate array for the data to be entered. Write a helper function called recursionMergeSort such that: It is a standalone function...
Python: How would I write a function that takes a directory and a size in bytes,...
Python: How would I write a function that takes a directory and a size in bytes, and returns a list of files in the directory or below that are larger than the size. For example, I can use this function to look for files larger than 1 Meg below my Home directory.
. NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE NEED NEW ANSWER ASAP / ANSWER...
. NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE NEED NEW ANSWER ASAP / ANSWER NEVER USED BEFORE Explain horizontal and vertical analysis. Do some research .explain why these methods are used. What can we learn from horizontal and vertical analysis statements? How can results vary compared to other corporations and why can ratios better than using dollars? ANSWER THROUGHLY 1 page *** IN PARAGRAPGH FORM PLEASE NOT BULLET POINTS COPY AND PASTE Answer in paragraphs, and no picture...
Need a python code for LU factorization( for partial pivoting and complete pivoting) of a random...
Need a python code for LU factorization( for partial pivoting and complete pivoting) of a random matrix size 5x5.
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): A website requests an user to input his account password. Write a program to examize the validity of the password. The valid password must consists of: At least 1 letter in [a-z] At least 1 number in [0-9] At least a letter in [A-Z] (capital) At least one special letter in [$#@] At least...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted...
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
(In python) Write a function calc_pizza_charge that takes four integer arguments, one for the size (1...
(In python) Write a function calc_pizza_charge that takes four integer arguments, one for the size (1 small, 2 medium, 3 large), one for the number of meat toppings, one for the number of other toppings and another for the quantity of pizzas ordered. It should calculate and return the total due for that pizza order based on the following information: Small pizza base price: $6.50 Medium pizza base price: $9.50 Large pizza base price: $11.50 The base pizza price includes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT