In demo.py Write a Python function that creates a window of size 320 by 320Īnd draws a grid of 8 by 8 squares, each of size 40 by 40 pixels, andĬolored a random color of red, green or blue. Tkinter Canvas: initialization and drawing rectangles on canvasĬ = Canvas(window, width = 300, height = 500) Has a top left coordinate of (100,100) and bottom right coordinateĬ.create_rectangle(100, 100, 110, 110, fill ="red", outline="blue") Part 1 - Random Numbers with Graphics 1.1. Right corners along with additional optional parameters:Ĭ.create_rectangle(topleft_x, topleft_y, bottomright_x, bottomright_y, optional parameter(s))įor example, to create a red square with a blue border that Rectangle and supply the coordinates of the top left and bottom To draw a rectangle using the Canvas, you need to create a new So the origin (0,0) is in the top left corner Left to right, but the y coordinates increase from top The coordinate system is upside down from what you The width and height are expressed as a number of pixels. Where you replace and with appropriate values. #Then, create our canvas and pack it into the display window # First, create the window where our canvas will be displayed # Canvas object only can be called by itself. # Remember, this means tkinter._ to call functions and objects In order to draw in Python, you need to create a Canvas which you Use the module random to generate random integers.Draw rectangles on the canvas, possibly with borders, and possibly filled with color and.Explain how the coordinate system works in the module Canvas.When you are done with this lab, you should be able to do the following: That part is mainly intended to make you think recursivelyĪnd enjoy a beautiful application of recursion. Last question and make you observe the recursive nature ofįractals. After we learn how toĭraw rectangles, we introduce the concept of a fractal in the Generate random colors for the shapes we draw. We will also be using the module random to We will be using the module Canvasįrom tkinter. This lab is intended to develop your understanding of doing simple
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |