Week 11: Exercises

1. Random Lines

Write a Tkinter program that draws 1000 random lines of length 300 pixels, each with a random color. All line angles should be equally likely.

2. Czech Flag

Write a Tkinter program that draws a Czech flag:

Do not use any external image files – instead, the program should draw the flag itself using filled rectangles and/or polygons.

3. Victory Line

Modify the Tic-Tac-Toe program from the lecture so that when one player wins, it draws a line through the winning squares.

4. Turn to Play

Modify the Tic-Tac-Toe program from the lecture so that it indicates whose turn it is to move.

5. Drawing Lines

Write a Tkinter program that lets the user draw lines. Initially the program should display a blank canvas. If the user clicks and drags the mouse, the program should display a line from the point where the user clicked to the current mouse position. When the user releases the mouse, the line should remain on the canvas. Each line should have a random color.

6. Drawing Squares

Write a program that lets the user draw squares by dragging the mouse. Each square should have a random color.

7. Dragging Squares

Extend the previous program so that the user can move a square to a new position by clicking and dragging it. A moved square should rise to the top of the Z-order.