Tkinter Shop

Objects

# Single Object

shopItem = {
    title: "Doritos",
    price: 0.99,
    image: "images/doritos.png"
}

shopItem["title"] # Doritos
shopItem["price"] # 0.99
shopItem["image"] # images/doritos.png

# List of Objects

items = [
    {
        title: "Doritos",
        price: 0.99,
        image: "images/doritos.png"
    },
    {
        title: "Mountain Dew",
        price: 1.20,
        image: "images/mtndew.png"
    }
]

shopItem[0]["title"] # Doritos
shopItem[1]["title"] # Mountain Dew
# Iterating Through a List of Objects

for item in items:
    print(item["name"])

# Doritos
# Mountain Dew

Product List Window

  1. Make a List of Objects to store all the items in your shop. Think of what information you'll need to store.
  2. Using the code last week, make a product list window
doritoImage = tkinter.PhotoImage(file="dorito.png")
button = tkinter.Button(window, image=doritoImage)
button.pack()

Tkinter Shop

By Jake Walker

Tkinter Shop

  • 594