Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. import tkinter as tk
  2. import menuUi
  3. import os
  4. import sys
  5. sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
  6. from services import getPriceList
  7.  
  8.  
  9. class PriceListUi(tk.Frame):
  10. def __init__(self, parent, controller):
  11. tk.Frame.__init__(self, parent, bg="#5A6D7C")
  12. screen_width = self.winfo_screenwidth() #Gets the screen width
  13. screen_height = self.winfo_screenheight() #Gets the screen height
  14. self.winfo_toplevel().configure(bg="#5A6D7C") # Changes background color of frame
  15. self.winfo_toplevel().geometry(str(screen_width)+"x"+str(screen_height)) #Sets the size of frame
  16.  
  17.  
  18.  
  19.  
  20.  
  21. bilaleigaTinna = tk.Label(self, text="Bílaleiga Tinna",bg="#5A6D7C",fg="white") #Creating labels and one frame
  22. label1 = tk.Label(self, text="Verðskrá",bg="#5A6D7C",fg="white")
  23. frame1 = tk.Frame(self,
  24.  
  25. bd=4,
  26. relief="ridge",
  27. highlightbackground="white",
  28. highlightcolor="white",
  29. bg = "#5A6D7C")
  30.  
  31. line1 = tk.Label(self, text="_____________________________",bg="#5A6D7C",fg="white")
  32. line2 = tk.Label(self, text="_____________________________",bg="#5A6D7C",fg="white")
  33.  
  34. smabill = tk.Label(frame1, text="Smábíll",bg="#5A6D7C",fg="white",width=22, height=2) #Putting labels in the frame
  35. folksbill = tk.Label(frame1, text="Fólksbíll",bg="#5A6D7C",fg="white",width=22, height=2)
  36. jeppi = tk.Label(frame1, text="Jeppi",bg="#5A6D7C",fg="white",width=22, height=2)
  37. luxusbill = tk.Label(frame1, text="Lúxusbíll",bg="#5A6D7C",fg="white",width=22, height=2)
  38.  
  39.  
  40.  
  41.  
  42. #Create Buttons
  43. self.edit = tk.Button(self, text="Uppfæra", bg="#448F42", fg="white", width=10, height=1, command=lambda: editPriceList(self))
  44. self.escape_button = tk.Button(self, text="Esc - Til baka", bg="#9E4848", fg="white", width=15, height=1, command=lambda: esc(controller))
  45.  
  46.  
  47. # create service file and connect to data access and make edit work#
  48. self.instance = getPriceList.GetPriceList()
  49. row_num = 1
  50. column_num = 10
  51.  
  52.  
  53. self.listOfPrice = []
  54. self.listofEntry = []
  55. for item in self.instance.priceListDataAccess.pricelist:
  56. self.label4 = tk.Label(frame1, text="{:,} kr.".format(int(item)) ,bg="#5A6D7C",fg="white", width=10, height=2)
  57. self.entry = tk.Entry(frame1)
  58. self.listofEntry.append(self.entry)
  59. self.entry.insert(0,item)
  60. self.listOfPrice.append(self.label4)
  61. self.label4.config(font=("Courier", 16))
  62. self.label4.grid(row = row_num, column=column_num)
  63. row_num+=1
  64.  
  65. #configure labels
  66. bilaleigaTinna.config(font=("Courier", 32))
  67. label1.config(font=("Courier", 28))
  68. line1.config(font=("Courier", 28))
  69. line2.config(font=("Courier", 28))
  70. self.edit.config( font=("Courier", 16))
  71. self.escape_button.config( font=("Courier", 16))
  72. smabill.config(font=("Courier", 16))
  73. folksbill.config(font=("Courier", 16))
  74. jeppi.config(font=("Courier", 16))
  75. luxusbill.config(font=("Courier", 16))
  76.  
  77.  
  78.  
  79. #Positioning labels,buttons and frame
  80. bilaleigaTinna.grid(row=1, column=3)
  81. label1.grid(row=3, column=3)
  82. frame1.grid(row=7, column=3)
  83. line1.grid(row=2,column=3)
  84. line2.grid(row=10,column=3)
  85. self.escape_button.grid(row=11, column=0,columnspan = 4)
  86. self.edit.grid(row=11, column=3 ,columnspan = 5)
  87. smabill.grid(row=1,column=1)
  88. folksbill.grid(row=2,column=1)
  89. jeppi.grid(row=3,column=1)
  90. luxusbill.grid(row=4,column=1)
  91.  
  92.  
  93. self.grid_rowconfigure(0, weight=2) #Spaces inbetween rows
  94. self.grid_rowconfigure(2, weight=0)
  95. self.grid_rowconfigure(1, weight=0)
  96. self.grid_rowconfigure(4, weight=1)
  97. self.grid_rowconfigure(3, weight=1)
  98. self.grid_rowconfigure(11, weight=1)
  99. self.grid_rowconfigure(9, weight=1)
  100. self.grid_rowconfigure(12, weight=3)
  101.  
  102. self.grid_columnconfigure(0, weight=2) #Spaces inbetween columns
  103. self.grid_columnconfigure(7, weight=2)
  104.  
  105.  
  106.  
  107. def editPriceList(self):
  108. for price in self.listOfPrice:
  109. price.grid_forget()
  110. self.escape_button.grid_forget()
  111. self.edit.grid_forget()
  112. self.change = tk.Button(self, text="Uppfæra", bg="#448F42", fg="white", width=10, height=1, command=lambda: changePriceList(self))
  113. self.back_button = tk.Button(self, text="Esc - Til baka", bg="#9E4848", fg="white", width=15, height=1, command=lambda: showoldinfo(self))
  114. self.change.config( font=("Courier", 16))
  115. self.back_button.config( font=("Courier", 16))
  116. self.change.grid(row=11, column=3 ,columnspan = 5)
  117. self.back_button.grid(row=11, column=0,columnspan = 4)
  118. entry_row_num = 1
  119. entry_column_num = 10
  120. for item in self.listofEntry:
  121. item.grid(row = entry_row_num, column=entry_column_num)
  122. entry_row_num+=1
  123.  
  124. def showoldinfo(self):
  125. self.back_button.grid_forget()
  126. self.change.grid_forget()
  127. for item in self.listofEntry:
  128. item.grid_forget()
  129. self.escape_button.grid(row=11, column=0,columnspan = 4)
  130. self.edit.grid(row=11, column=3 ,columnspan = 5)
  131. self.instance = getPriceList.GetPriceList()
  132. row_num = 1
  133. column_num = 10
  134. self.listOfPrice = []
  135. self.listofEntry = []
  136. for item in self.instance.priceListDataAccess.pricelist:
  137. self.label4 = tk.Label(frame1, text="{:,} kr.".format(int(item)) ,bg="#5A6D7C",fg="white", width=10, height=2)
  138. self.entry = tk.Entry(frame1)
  139. self.listofEntry.append(self.entry)
  140. self.entry.insert(0,item)
  141. self.listOfPrice.append(self.label4)
  142. self.label4.config(font=("Courier", 16))
  143. self.label4.grid(row = row_num, column=column_num)
  144. row_num+=1
  145.  
  146.  
  147. def changePriceList(self):
  148. try:
  149. listi=[]
  150. for self.price in self.listofEntry:
  151. self.newprice = self.price.get()
  152. if int(self.newprice) < 0:
  153. showoldinfo(self)
  154. return
  155. listi.append(self.newprice)
  156. self.instance.editPriceList(listi)
  157. showoldinfo(self)
  158. except Exception:
  159. showoldinfo(self)
  160.  
  161.  
  162.  
  163.  
  164. def esc(self):
  165. controller.show_frame(menuUi.MenuUi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement