I Can Has Cheezburger?

A graphical interface to get some fast food

avatar

Sébastien Boisgérault
Associate Professor, ITN Mines Paris – PSL

Photo by sk on Unsplash

At the beginning …

Flet is a Python library for building graphical user interfaces.

Implement the example given in its documentation to get familiar with it.

Flet counter

Graphical Architecture

Develop the graphical architecture of a menu ordering application, represented in the figure below:

Graphical user interface for menu order

You will have to explore the documentation of the components offered by flet.

At first:

You can use https://emojipedia.org to find the emojis you need (🍔 hamburger, 🍟 fries, etc.)

Custom Component

The flet documentation explains how you can create your own components. Used wisely, this possibility should allow you to make the architecture of your command application more readable.

Ideally, we would like to have a Product component that takes care of the representation of a product, the display of its price as well as the counting of the number of units that the customer wishes to order. The resulting application could then take the following form:

from flet import app, icons
from flet import MainAxisAlignment
from flet import (
    Card,
    Column,
    Container,
    Divider,
    FilledButton,
    IconButton,
    Markdown,
    Row,
    Text,
    TextField,
)

from product import Product


def main(page):
    page.title = "I Can Has Cheezburger?"
    page.window_width = 400
    page.window_height = 430
    page.add(
        Column(
            alignment=MainAxisAlignment.CENTER,
            controls=[
                Product("🍔", 5.95),
                Product("🍟", 3.60),
                Product("🥗", 8.30),
                Product("🥤", 2.60),
                Divider(),
                Row(
                    [
                        Card(
                            Container(
                                Markdown(
                                    "**TOTAL:** 0.00 €"
                                ),
                                padding=10,
                            )
                        ),
                        FilledButton(
                            text="Buy", icon=icons.PAYMENT
                        ),
                    ],
                    alignment=MainAxisAlignment.SPACE_BETWEEN,
                ),
            ],
        )
    )


app(target=main)

Develop a class Product in a file product.py so that this new program works (as before).

Locally Functional Component

Make sure that the Product component is functional locally. That is to say, that the buttons + and - of a product only affect the quantity of this product and not the quantity of another product. Do not worry about the total of the order for the moment. However, make sure that the quantity of a product cannot be negative.

Fully Functional Component

Two things are missing from our product component:

Make the necessary changes to the Product component so that it is fully functional.

Integration

Complete your application so that the total of the order is always up to date.