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

7 years ago
  1. # import saveto
  2. import datetime
  3. from decimal import Decimal as D
  4. from tkinter import *
  5. def dicter(l):
  6. ret = {}
  7. for thing in l:
  8. name = thing['name']
  9. ret[name] = thing
  10. return ret
  11. def message(qpb,qpd):
  12. qpb,qpd = map(dicter,(qpb,qpd))
  13. def button_callback(arg):
  14. check_boxes[arg].toggle()
  15. prods = list(filter(lambda item: not item[1]['purchased'],qpb.items()))
  16. root = Tk()
  17. checks = dict(
  18. (prod[0],BooleanVar()) for prod in prods)
  19. root.wm_title("Today's Prices")
  20. labels = ["","Product name","Price","Count","Total"]
  21. for i,label in enumerate(labels):
  22. Label(root,text = label).grid(row =0,column = i)
  23. row = 1
  24. total = 0
  25. single_total = 0
  26. buttons = []
  27. check_boxes = []
  28. for prod,data in prods:
  29. check_boxes.append(
  30. Checkbutton(root,variable=checks[prod],state = DISABLED)
  31. )
  32. check_boxes[-1].grid(row = row,column = labels.index(""),stick=E)
  33. buttons.append(
  34. Button(
  35. root,text=prod,command = lambda row=row-1: button_callback(row)
  36. )
  37. )
  38. buttons[-1].grid(row=row,column = labels.index("Product name"),sticky = E+W)
  39. price = D(qpd[prod]['price'])
  40. row_total = data['count']*price
  41. Label(root,text = '${}'.format(price),relief = "sunken").grid(row = row,column=labels.index('Price'),sticky=E+W)
  42. Label(root,text = data['count'],relief = "sunken").grid(row=row,column=labels.index('Count'),sticky = E+W)
  43. Label(root,text = '${}'.format(row_total),relief = "sunken").grid(row = row,column=labels.index("Total"),sticky=E+W)
  44. total += row_total
  45. single_total += price
  46. row += 1
  47. Label(root,text = "Total:").grid(row = row,column=labels.index("Count"))
  48. Label(root,text = "Individual:").grid(row = row,column=labels.index("Product name"),sticky = E)
  49. Label(root,text = "${}".format(total)).grid(row=row,column = labels.index("Total"))
  50. Label(root,text = "${}".format(single_total)).grid(row=row,column=labels.index("Price"))
  51. Button(root,text = "OK", command = root.quit).grid(row=row+2)
  52. root.overrideredirect(True)
  53. root.wm_attributes("-topmost", True)
  54. mainloop()
  55. root.destroy()
  56. for key in checks.keys():
  57. checks[key] = checks[key].get()
  58. return checks