gui.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from tkinter import *
  2. from linked_data import Chain, format_dict
  3. import pprint
  4. chain = Chain()
  5. chain.populate()
  6. root = Tk()
  7. root.title('dsp blockchain')
  8. view = Entry(root, width=35, borderwidth=5)
  9. view.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  10. def myClick():
  11. print(view.get())
  12. chain.current_contract_state(int(view.get()))
  13. pprint.pprint(chain.state)
  14. def add_contract():
  15. # add contract to the blockchain
  16. def add():
  17. chain.new_contract(client.get(), contractor.get(), deadline.get(), description.get(), name.get(), int(price.get()), people.get().split(','), initiator.get())
  18. # destroy add contract window, and print conformation
  19. newWindow.destroy()
  20. print('contract added')
  21. # make new window for adding the information for the contract
  22. newWindow = Toplevel(root)
  23. newWindow.title('Add contract')
  24. # create all text boxes
  25. Label(newWindow, text='The client: ').grid(row=0, column=0)
  26. client = Entry(newWindow, width=35, borderwidth=5)
  27. client.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  28. Label(newWindow, text='The contractor: ').grid(row=1, column=0)
  29. contractor = Entry(newWindow, width=35, borderwidth=5)
  30. contractor.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  31. Label(newWindow, text='Deadline: ').grid(row=2, column=0)
  32. deadline = Entry(newWindow, width=35, borderwidth=5)
  33. deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  34. Label(newWindow, text='Description: ').grid(row=3, column=0)
  35. description = Entry(newWindow, width=35, borderwidth=5)
  36. description.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  37. Label(newWindow, text='Project name: ').grid(row=4, column=0)
  38. name = Entry(newWindow, width=35, borderwidth=5)
  39. name.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
  40. Label(newWindow, text='Price: ').grid(row=5, column=0)
  41. price = Entry(newWindow, width=35, borderwidth=5)
  42. price.grid(row=5, column=1, columnspan=3, padx=10, pady=10)
  43. Label(newWindow, text='People involved: ').grid(row=6, column=0)
  44. people = Entry(newWindow, width=35, borderwidth=5)
  45. people.grid(row=6, column=1, columnspan=3, padx=10, pady=10)
  46. Label(newWindow, text='Initiator').grid(row=7, column=0)
  47. initiator = Entry(newWindow, width=35, borderwidth=5)
  48. initiator.grid(row=7, column=1, columnspan=3, padx=10, pady=10)
  49. # create the add contract button
  50. add_c = Button(newWindow, text = "Add contract", command=add)
  51. add_c.grid(row=8, column=0)
  52. myButton = Button(root, text="View contract", command=myClick)
  53. myButton.grid(row=0, column=0)
  54. myButton = Button(root, text="New contract", command=add_contract)
  55. myButton.grid(row=1, column=0)
  56. root.mainloop()