Introduction
This is a demonstration of one way to develop a TK program. It is
an incremental approach.
This will be simple drawing program demonstrating a drawing area.
With each step you do a few line of code, then test
and debug it. It this way you accumulate more and more detail and functionality.
step 1 - write simple requirements
For example:
- There will be a drawing area
- Lines can be drawn on the drawing area
- When the cursor is over the drawing area and a button
held down, draw pixel(s) at that location
- As the cursor moves a line is drawn
- The drawing area background color can be changed
- The drawing area background color is selected from a minimum
of four different colors
- The line drawing color can be changed
- The line drawing color is selected from a minimum
of four different colors
- There will be a "quit program" capability
- The drawing areas can be reset to a default background and line color
- Resizing will not be allowed
Note: this is not a set of formal requirements. This is for your use.
It is to prevent requirements creep.
Step 2 - design decisions
- Program will be coded in Python 3
- A Canvas widget will be the drawing area
- Buttons will be used to select the drawing area background color
- Buttons will be used to select the line color
- Color buttons background color will be the color
- Color buttons text will define the color
- A button will be used to quit the program
- A button will be used to reset the drawing area
- The left mouse button will be used to draw lines
- Lines will not be strait but ragged as the cursor moves
- The title "Drawing Program" will be a TK label at the top
Note: this is not a formal design. This is for your use.
It is to prevent design creep.
Steps 3 - preliminary layout
On paper, draw a layout for the program. For example:
Note: this is not a formal layout. This is for your use.
It is to prevent layout changes during development.
Steps 4 - incremental code and testing
Increment 1
Increment 2
Increment 3
Increment 4
Increment 5
Continue adding code and testing
Step 5 - cleanup and comment code, and document program