Components of a mobile application

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

Components of a mobile application

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A button, a text box and a label on a screen are examples of which mobile app component?
A Interface controls on a screen
B External libraries
2. Which describes an object in a mobile app?
A It is a screen that only displays pictures
B It holds data and behaviour together, like a Player with a score and a jump action
3. A user taps the Save button and the app stores their note. Which component responds to the tap?
A An event handler
B A label control
4. Which statement about event handlers is correct?
A They run only once, when the app is first installed
B They run in response to a user action such as a tap or swipe
5. Your team adds a ready-made maps library so the app can show a map. What is a library?
A Ready-made code written by others that your app can reuse
B A folder where the app stores user photos

Match the Pairs

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

Left columnRight column
1button.onClick(save_score) ABrings in a library of ready-made code, such as map features, so the app does not need to build them
2import maps_library Bscreen.add(Label('Score'), Button('Play'))
3An object holds data (attributes) and behaviour (methods) together Cplayer = Player('Ava', 120) player.add_points(10)
4A screen is made from interface controls such as labels and buttons that the user sees and taps DThe object's data is mixed up: a text value is added to a number, which causes an error. Score should hold a number, such as player.score = 10 + 5.
5button.onClick(save_score()) EThe handler is called straight away because of the brackets, so it runs when the screen loads, not when the user taps. Pass the function name without brackets.
6player.score = 'ten' + 5 FAn event handler: when the user taps the button, the save_score function runs

Definitions

app components

Fill in the Blanks

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

1.
btn = ______(root, text="Go", command=start)
2.
class Player: def ________(self, name): self.name = name
3.
btn = Button(root, _______=on_tap)
4.
______ requests data = requests.get(url)
5.
root = Tk() label = Label(root, text="Score") root.________()

Spot the Error

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

Question 1
A w = tk.Tk()
B lbl = tk.Label(text="Hi", w)
C lbl.pack()
D w.mainloop()
Question 2
A def go():
B print("Tapped")
C b = tk.Button(w, command=go())
D b.pack()
Question 3
A class Task:
B def __init__(self, name):
C name = name
D t = Task("Homework")
Question 4
A import Random
B dice = random.randint(1, 6)
C print(dice)
Question 5
A import tkinter as tk
B w = tk.Window()
C box = tk.Entry(w)
D box.pack()

Answer Key

Components of a mobile application
Section A: Quick Questions
Q1
A — Interface controls on a screen
Q2
B — It holds data and behaviour together, like a Player with a score and a jump action
Q3
A — An event handler
Q4
B — They run in response to a user action such as a tap or swipe
Q5
A — Ready-made code written by others that your app can reuse
Section B: Match the Pairs
Q1
button.onClick(save_score) → An event handler: when the user taps the button, the save_score function runs
Q2
import maps_library → Brings in a library of ready-made code, such as map features, so the app does not need to build them
Q3
An object holds data (attributes) and behaviour (methods) together → player = Player('Ava', 120) player.add_points(10)
Q4
A screen is made from interface controls such as labels and buttons that the user sees and taps → screen.add(Label('Score'), Button('Play'))
Q5
button.onClick(save_score()) → The handler is called straight away because of the brackets, so it runs when the screen loads, not when the user taps. Pass the function name without brackets.
Q6
player.score = 'ten' + 5 → The object's data is mixed up: a text value is added to a number, which causes an error. Score should hold a number, such as player.score = 10 + 5.
Section C: Definitions
Q1
app components — The parts that make up a mobile app: interface controls on screens, objects with data and behaviour, event handlers that respond to the user, and libraries of ready-made code.
Section D: Fill in the Blanks
Q1
btn = Button(root, text="Go", command=start)
Q2
class Player: def __init__(self, name): self.name = name
Q3
btn = Button(root, command=on_tap)
Q4
import requests data = requests.get(url)
Q5
root = Tk() label = Label(root, text="Score") root.mainloop()
Section E: Spot the Error
Q1
B — The parent window w is a positional argument and must come before the keyword argument text=. The correct line is lbl = tk.Label(w, text="Hi"), which puts the Label control on the screen.
Q2
C — Writing go() runs the handler straight away and passes its result to the button. The button needs the handler itself, so use command=go with no brackets. Then go runs when the user taps.
Q3
C — This only changes a local variable, so the object never stores its data. It should be self.name = name, so the Task object keeps the name.
Q4
A — Python module names are case-sensitive. The library is called random in lowercase, so it must be imported as import random before its code can be used.
Q5
B — tkinter has no Window class. The main app window is created with tk.Tk(), so the line should be w = tk.Tk().