Reading - Inheritance¶
(30-60 min)
Read through p.656, stopping before the
Programming Exercises.
“Is a” relationship¶
class Item:
def __init__(self, id: str, price_per_unit: Decimal):
self.id = id
self.price_per_unit = price_per_unit
def __str__(self) -> str:
return f"{self.id} ({self.price_per_unit} per unit)"
class HardItem(Item):
def __init__(self, id: str, price_per_unit: Decimal, unit_weight: Decimal):
super().__init__(id, price_per_unit)
self.unit_weight = unit_weight
def __str__(self) -> str:
return super().__str__() + f" {self.unit_weight} kg per unit"Polymorphism¶
For example: Both Item and HardItem have __init__. The __init__ functions of Item and HardItem are similar but not exactly the same.
from decimal import Decimal
item1 = Item(id="hydraulic pump", price_per_unit=Decimal("20"))
item2 = HardItem(id="lubrication oil", price_per_unit=Decimal("10.1"), unit_weight=Decimal(".2"))
print(item1)
print(item2)hydraulic pump (20 per unit)
lubrication oil (10.1 per unit) 0.2 kg per unit
Tk installation¶
Needed for GUI Programming. Run the following command in the terminal of your editor to see whether Tk is installed or not:
python -m tkinterIf you don’t see any window, follow https://
Reading - GUI Programming¶
(2-4h)
Read through p.765, stopping before the
Programming Exercises.
Graphical user interfaces (GUI)¶
command line interface vs GUI
GUI programs are based on event-driven programming
your program must be able to respond to GUI events.
tkinter¶
the reading uses old way of
tkinter-based GUI programmingA modern tutorial: https://
tkdocs .com /tutorial /firstexample .html according to the tutorial the following must be avoided:
non-themed classic widgets for buttons, frames, etc must be avoided
“Pack” geometry manager
Basic Widgets¶
https://
Frame
for organizing
Label
Button
Checkbutton
Radiobutton
Entry
Combobox
Treeview for tables https://
tkdocs .com /tutorial /tree .html