Hungarian notation for interface controls

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Hungarian notation for interface controls

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which name follows Hungarian notation for a button that submits a form?
A btnSubmit
B submit
2. Which prefix is normally used for a textbox control that accepts a student's name?
A lblName
B txtName
3. True or false: the prefix in lblResult tells you the control is a label.
A True
B False
4. Which control name describes what the control does, as well as its type?
A btnCalculateTotal
B btn1
5. Which name is a good choice for a listbox that shows a list of products?
A cboProducts
B lstProducts

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1txtFirstName AcboYearLevel
2lblResult BbtnSave
3A button control that saves the entered data, named with the correct type prefix and purpose CThe name has no type prefix and does not describe its purpose. It should be something like btnSubmit.
4A combobox control for choosing a year level, named with the combobox prefix DA label control used to display a result to the user
5button1 = Button(window, text="Submit") EThe prefix lst means a list, but an Entry is a textbox. The name should use txt, such as txtName.
6lstNames = Entry(window) FA textbox control that collects the user's first name

Definitions

btnSubmit

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___Submit = Button(window, text="Submit")
2.
___Name = Entry(window) name = txtName.get()
3.
___Result = Label(window, text="") lblResult.pack()
4.
___Students = Listbox(window) lstStudents.pack()
5.
___House = Combobox(window) print(cboHouse.get())

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A txtName = Entry(root)
B lblResult = Label(root)
C txtSubmit = Button(root)
Question 2
A btnNames = Listbox(root)
B btnAdd = Button(root)
C lblTotal = Label(root)
Question 3
A cboHouse = Combobox(root)
B lblPoints = Entry(root)
C btnSave = Button(root)
Question 4
A txtAge = Entry(root)
B lblAge = Label(root)
C btnCheck = Button(root)
D result = Label(root)
Question 5
A cboYear = Combobox(root)
B btnEnter = Button(root)
C lbl1 = Label(root)

Answer Key

Hungarian notation for interface controls
Section A: Quick Questions
Q1
A — btnSubmit
Q2
B — txtName
Q3
A — True
Q4
A — btnCalculateTotal
Q5
B — lstProducts
Section B: Match the Pairs
Q1
txtFirstName → A textbox control that collects the user's first name
Q2
lblResult → A label control used to display a result to the user
Q3
A button control that saves the entered data, named with the correct type prefix and purpose → btnSave
Q4
A combobox control for choosing a year level, named with the combobox prefix → cboYearLevel
Q5
button1 = Button(window, text="Submit") → The name has no type prefix and does not describe its purpose. It should be something like btnSubmit.
Q6
lstNames = Entry(window) → The prefix lst means a list, but an Entry is a textbox. The name should use txt, such as txtName.
Section C: Definitions
Q1
btnSubmit — Hungarian notation for a control: a type prefix (btn button, txt textbox, lbl label, lst list, cbo combobox) plus a purpose, so btnSubmit is clearly a button.
Section D: Fill in the Blanks
Q1
btnSubmit = Button(window, text="Submit")
Q2
txtName = Entry(window) name = txtName.get()
Q3
lblResult = Label(window, text="") lblResult.pack()
Q4
lstStudents = Listbox(window) lstStudents.pack()
Q5
cboHouse = Combobox(window) print(cboHouse.get())
Section E: Spot the Error
Q1
C — A Button control should use the btn prefix, not txt. txtSubmit makes it look like a textbox. It should be btnSubmit.
Q2
A — A Listbox should use the lst prefix. btnNames suggests a button. It should be lstNames.
Q3
B — An Entry is a textbox, so it needs the txt prefix, not lbl. A label only displays text. It should be txtPoints.
Q4
D — The name has no type prefix, so you cannot tell it is a label. The control should be named lblResult.
Q5
C — The prefix is right, but the name 1 does not say what the control does. A control should be named for its purpose, such as lblError.