M06 Assignments

Introduction

The lessons for M06 focus on building GUI (Graphical User Interface) programs.

M06_Assignments

General Requirements

Instead of a banner, include your name or initials in the main window title.

Exercise #1 (Hello World)

This is the simplest GUI program you can create. The objective here is to simply get a working GUI program under your belt.

Create a Hello World program. It will only have a single window. The only requirements are

  1. add your name or initials to the window title (per the standards)
  2. display Hello World on the window

Extra credit available: Display "Hello World" in a large font (3 points); change the color on the text (other than black) or window (other than white) or both (3 points)

Testing: Your results should look similar to the image below.

Hello World Sample Display
Figure 1: M05 Assn1 Ex1: Hello World Sample Display

Exercise #2 (Temperature Converter)

Write a GUI program that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, then see the equivalent Fahrenheit temperature. Use the following formula to make the conversion: F=95C+32, where F is the Fahrenheit temperature, and C is the Celsius temperature. (Do NOT use F and C as variable names - use meaningful variable names).

The user should be able to enter a generic temperature, and then click one of 3 buttons:

  1. convert to Fahrenheit
  2. convert to Celsius
  3. clear the form

Display the results as a Label, not a Text Box.

Testing: Your results should look similar to the image below, although it is not necessary to include colors and make the window fancy. I will test using the values 89 to converted Celsius and 32 to convert to Fahrenheit. I will also try to Clear the window.

Extra credit available: Validate the user input make sure it is not blank and display an error message if it is blank (3 points)

Temp Converter Sample Display 1
Figure 2: M06 Assn1 Ex2: Temperature Converter Sample Display 1: Empty Form
Temp Converter Sample Display 2
Figure 3: M06 Assn1 Ex2: Temperature Converter Sample Display 2: Convert to Celsius
Temp Converter Sample Display 3
Figure 4: M06 Assn1 Ex2: Temperature Converter Sample Display 3: Clear the Form
Temp Converter Sample Display 4
Figure 5: M06 Assn1 Ex2: Temperature Converter Sample Display : Convert to Fahrenheit
Temp Converter Sample Display 5
Figure 6: M06 Assn1 Ex2: Temperature Converter Sample Display 5: Validate User Input

Exercise #3 (Final Project Basic Form)

The goal of this assignment is to get your main window displayed with most of the labels, text boxes, and buttons (and other elements, if needed). None of the elements or buttons need to "do anything" (that is the next assignment). You do not need to worry about fonts, colors or anything else in terms of style, unless you wish to do that at this stage. You do not need to create a button for or plan for a second window at this point.

Create your program file. You must make several decisions about how to proceed with the basic design. Among these are:

  • whether to use plain TKinter or using the breezypythongui library referenced in the book
  • a naming scheme for your UI elements
  • whether to primarily use the grid system or x/y coordinates to position your UI elements

There are a series of articles on GUI Coding on this site, that walks through creating a GUI program based on standard TKinter coding. It is an alternate to using the breezypythongui library listed in the book.

Screen display of the instructors sample program for the Final Project:

Basic Form Sample Display
Figure 8: M06 Assn2 Ex3: Basic Form Sample Display

Exercise #4 (Clear the Form)

This assignment builds on Exercise 3. There are two goals:

  1. create a label message that can be used for errors and other information
  2. mock up the functions for any buttons

A message label will be used to display error messages or other information, as needed. It should normally be placed near the bottom of the window, and initially does not display anything. In this assignment, it can be used for task 2 above.

All main windows should have a Clear button to clear any text boxes. For this assignment, the task is to clear all text boxes on the window, and to update the message label with a message such as "Form cleared"; this will show the message label is positioned correctly and working.

Sample display of the instructors sample program for the clear button. The form itself does not change, but the function triggered by the clear button will delete the text from all text boxes and display a message. (This clear message may not ultimately be used, but for now it demonstrates how the message can be used.)

Sample Form with Text Boxes Filled In
Figure 9: M06 Assn2 Ex4: Sample Form with Text Boxes Filled In
Sample Form After Clear Button Clicked
Figure 10: M06 Assn2 Ex4: Sample Form After Clear Button Clicked