You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.3 KiB
71 lines
2.3 KiB
# import saveto
|
|
import datetime
|
|
from decimal import Decimal as D
|
|
from tkinter import *
|
|
def dicter(l):
|
|
ret = {}
|
|
for thing in l:
|
|
name = thing['name']
|
|
ret[name] = thing
|
|
return ret
|
|
def message(qpb,qpd):
|
|
qpb,qpd = map(dicter,(qpb,qpd))
|
|
def button_callback(arg):
|
|
check_boxes[arg].toggle()
|
|
prods = list(filter(lambda item: not item[1]['purchased'],qpb.items()))
|
|
|
|
root = Tk()
|
|
checks = dict(
|
|
(prod[0],BooleanVar()) for prod in prods)
|
|
|
|
root.wm_title("Today's Prices")
|
|
labels = ["","Product name","Price","Count","Total"]
|
|
for i,label in enumerate(labels):
|
|
Label(root,text = label).grid(row =0,column = i)
|
|
|
|
row = 1
|
|
total = 0
|
|
single_total = 0
|
|
buttons = []
|
|
check_boxes = []
|
|
for prod,data in prods:
|
|
|
|
check_boxes.append(
|
|
Checkbutton(root,variable=checks[prod],state = DISABLED)
|
|
)
|
|
|
|
check_boxes[-1].grid(row = row,column = labels.index(""),stick=E)
|
|
|
|
buttons.append(
|
|
Button(
|
|
root,text=prod,command = lambda row=row-1: button_callback(row)
|
|
)
|
|
)
|
|
|
|
buttons[-1].grid(row=row,column = labels.index("Product name"),sticky = E+W)
|
|
|
|
price = D(qpd[prod]['price'])
|
|
row_total = data['count']*price
|
|
|
|
Label(root,text = '${}'.format(price),relief = "sunken").grid(row = row,column=labels.index('Price'),sticky=E+W)
|
|
Label(root,text = data['count'],relief = "sunken").grid(row=row,column=labels.index('Count'),sticky = E+W)
|
|
Label(root,text = '${}'.format(row_total),relief = "sunken").grid(row = row,column=labels.index("Total"),sticky=E+W)
|
|
|
|
total += row_total
|
|
single_total += price
|
|
row += 1
|
|
|
|
Label(root,text = "Total:").grid(row = row,column=labels.index("Count"))
|
|
Label(root,text = "Individual:").grid(row = row,column=labels.index("Product name"),sticky = E)
|
|
Label(root,text = "${}".format(total)).grid(row=row,column = labels.index("Total"))
|
|
Label(root,text = "${}".format(single_total)).grid(row=row,column=labels.index("Price"))
|
|
Button(root,text = "OK", command = root.quit).grid(row=row+2)
|
|
|
|
root.overrideredirect(True)
|
|
root.wm_attributes("-topmost", True)
|
|
mainloop()
|
|
root.destroy()
|
|
|
|
for key in checks.keys():
|
|
checks[key] = checks[key].get()
|
|
return checks
|