This assignment is Homework 23, and is due at classtime on Wednesday, April 26.

Assignment

  1. Use a Tkinter canvas to draw the flag of some country. For example, the flag of France is shown below.

    flag of France

    Include a Quit button that closes your Tkinter window, as shown above.

  2. Create a Tkinter window with at least three buttons and a canvas. Each button should display the name of a different country. When the user clicks a button, the flag of that country should be drawn on the canvas.

    For example, your program might produce a window like this:

    flags of three countries
  3. Create a Tkinter window with a canvas and a button that causes a randomly-sized circle to be drawn at a randomly-selected location on the canvas. Then modify your program so that the fill colors of the circles are also chosen randomly. Random colors can be obtained with the following code:

    r = random.randrange(255)
    g = random.randrange(255)
    b = random.randrange(255)
    color = "#{:02x}{:02x}{:02x}".format(r, g, b)

    (The code above uses the Python's str.format() method to write three integers, formatted as hexadecimal numbers, in a string.)

    For example, your program might produce a window like this:

    random circles program

Submitting your work

After you have finished your solutions, paste all of your solutions into a single Python file. Use comments to clearly state the problem numbers corresponding to your code. Save your file and upload it to the HW23 assignment on Moodle.