Skip to content

Instantly share code, notes, and snippets.

@Akkiesoft
Created November 19, 2021 17:18
Show Gist options
  • Select an option

  • Save Akkiesoft/0659cebdf741bfe05398847938440c62 to your computer and use it in GitHub Desktop.

Select an option

Save Akkiesoft/0659cebdf741bfe05398847938440c62 to your computer and use it in GitHub Desktop.
from guizero import App, Box, PushButton, Text, ListBox
import sys
import json
cart = dict()
total = 0
def update_cart_list(l):
global total, listbox
result = list()
listbox.clear()
total = 0
for i,c in l.items():
subtotal = c * int(items[i]['price'])
total = total + subtotal
listbox.append(items[i]['short'] + ' x ' + str(c) + " ¥" + str(subtotal))
update_total()
def update_total():
global total_label
total_label.clear()
total_label.append("合計" + str(total))
def item_clicked(c):
if not c in cart:
cart[c] = 1
else:
cart[c] = cart[c] + 1
update_cart_list(cart)
def clear_cart():
global cart, total, listbox
cart = dict()
total = 0
listbox.clear()
update_total()
def do_nothing():
sys.exit()
with open('items.json') as f:
items = json.loads(f.read())
app = App(title="EjeCasher")
app.full_screen = True
itembox = Box(app, layout="grid", width="fill", align="left")
cartbox = Box(app, width="fill", align="left")
button = list()
for c,i in enumerate(items):
x = c % 3
y = int(c / 3) * 3
button.append(PushButton(itembox, grid=[x,y], image=i['image'], command=item_clicked, args=[c]))
Text(itembox, grid=[x,y+1], text=i['name'])
Text(itembox, grid=[x,y+2], text="¥"+i['price'])
Text(cartbox, text="選択した商品:")
listbox = ListBox(cartbox, width="fill", items=[])
clear_button = PushButton(cartbox, width="fill", text="キャンセル", command=clear_cart)
total_label = Text(cartbox, text="合計: ")
total_label.text_size = 20
pay_button = PushButton(cartbox, width="fill", text="購入", command=do_nothing)
app.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment