Advertisement
Vasilena

diplomna

Apr 5th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.14 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import *
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5. import tkinter.messagebox
  6. from pump_two_on import PumpTwoOn
  7. from pump_two_off import PumpTwoOff
  8. from pump_one_on import PumpOneOn
  9. from pump_one_off import PumpOneOff
  10. from auto import PumpAuto
  11. from exit import Exit
  12. import RPi.GPIO as GPIO
  13.  
  14.  
  15. GPIO.setwarnings(False)
  16. GPIO.setmode(GPIO.BOARD)
  17.  
  18. GPIO.setup(29, GPIO.IN)
  19. GPIO.setup(31, GPIO.IN)
  20. GPIO.setup(33, GPIO.IN)
  21. GPIO.setup(35, GPIO.IN)
  22. GPIO.setup(37, GPIO.IN)
  23.  
  24. class Window:
  25.  
  26. def __init__(self, root):
  27. # --------------------------------TK-------------------------------
  28. # root setup
  29. self.window = root
  30. self.background_color = '#999da0'
  31. self.window.attributes('-fullscreen', True)
  32. self.window.title("Control Panel")
  33. self.window.configure(background='#999da0')
  34.  
  35. #root geometry
  36. self.screen_width = self.window.winfo_screenwidth() # 1920
  37. self.screen_height = self.window.winfo_screenheight() # 1080
  38.  
  39. # manual mode
  40. self.manual = Label(root, text="РЪЧНО УПРАВЛЕНИЕ", font=('Arial', 30), bg=self.background_color, fg="black")
  41. self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 20)
  42.  
  43. self.pumpOne = Label(root, text="ПОМПА 1", font=('Arial', 20), bg=self.background_color, fg="black")
  44. self.pumpOne.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 8)
  45.  
  46. self.pumpTwo = Label(root, text="ПОМПА 2", font=('Arial', 20), bg=self.background_color, fg="black")
  47. self.pumpTwo.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 8)
  48.  
  49. # buttons
  50. self.pump_one_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_on_func,
  51. bg="#198FF5", fg="white")
  52. self.pump_one_on_btn.place(x=(self.screen_width / 3) * 2.18, y=self.screen_height / 5.8)
  53. self.pump_one_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_off_func,
  54. bg="#696969", fg="white")
  55. self.pump_one_off_btn.place(x=(self.screen_width / 3) * 2.16, y=self.screen_height / 4.5)
  56.  
  57. # separator
  58. self.separator_frame = Frame(root, bg="black", width=2, height=150)
  59. self.separator_frame.place(x=1590, y=137)
  60.  
  61. self.pump_two_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_on_func,
  62. bg="#198FF5", fg="white")
  63. self.pump_two_on_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 5.8)
  64. self.pump_two_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
  65. bg="#696969", fg="white")
  66. self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 4.5)
  67.  
  68. # draning
  69. self.manual = Label(root, text="ГЛАВЕН РЕЗЕРВОАР", font=('Arial', 30), bg=self.background_color, fg="black")
  70. self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 3.3)
  71.  
  72. self.pump_two_off_btn = Button(root, text="ИЗТОЧВАНЕ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
  73. bg="#F06B5D", fg="white")
  74. self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.35, y=self.screen_height / 2.7)
  75.  
  76. # separator
  77. self.separator_frame = Frame(root, bg="black", width=470, height=2)
  78. self.separator_frame.place(x=1360, y=480)
  79.  
  80. # exit program button
  81. self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
  82. command=self.Exit_btn_func, bg="#EF4324", fg="white")
  83. self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
  84.  
  85. # automatic mode
  86. self.automatic = Label(root, text="АВТОМАТИЧНО УПРАВЛЕНИЕ", font=('Arial', 25), bg=self.background_color, fg="black")
  87. self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
  88.  
  89. self.tankOne = Label(root, text="РЕЗЕРВОАР 1", font=('Arial', 20), bg=self.background_color, fg="black")
  90. self.tankOne.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.9)
  91.  
  92. # separator
  93. self.separator_frame = Frame(root, bg="black", width=2, height=120)
  94. self.separator_frame.place(x=1590, y=570)
  95.  
  96. self.tankTwo = Label(root, text="РЕЗЕРВОАР 2", font=('Arial', 20), bg=self.background_color, fg="black")
  97. self.tankTwo.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.9)
  98.  
  99. # dropdown menus
  100. self.tank1_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  101. self.tank1_label.place(x=(self.screen_width / 3) * 2.17, y = self.screen_height / 1.7)
  102. self.tank1_value_inside = tk.StringVar(value="0%")
  103. self.tank1_options = ["0%", "20%", "40%", "60%", "80%","100%"]
  104. self.tank1_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank1_options)
  105. self.tank1_dropdown.place(x=(self.screen_width / 3) * 2.32, y = self.screen_height / 1.7)
  106.  
  107. # dropdown menus
  108. self.tank2_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  109. self.tank2_label.place(x=(self.screen_width / 3) * 2.55, y = self.screen_height / 1.7)
  110. self.tank2_value_inside = tk.StringVar(value="0%")
  111. self.tank2_options = ["0%", "20%", "40%", "60%", "80%","100%"]
  112. self.tank2_dropdown = tk.OptionMenu(root, self.tank2_value_inside, *self.tank2_options)
  113. self.tank2_dropdown.place(x=(self.screen_width / 3) * 2.70, y = self.screen_height / 1.7)
  114.  
  115. # sequence option
  116. self.automatic = Label(root, text="ИЗБЕРИ ПОСЛЕДОВАТЕЛНОСТ", font=('Arial', 25), bg=self.background_color, fg="black")
  117. self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 1.5)
  118.  
  119. # create a label and two radio buttons for the first sequence option
  120. self.sequence1_label = tk.Label(root, text='ЕДНО', bg=self.background_color, font=('Arial', 20))
  121. self.sequence1_label.place(x=(self.screen_width / 3) * 2.3, y=self.screen_height / 1.4)
  122.  
  123. self.sequence1_var = tk.StringVar(root)
  124. self.sequence1_var.set('Резервоар 1')
  125.  
  126. self.sequence1_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color,font=('Arial', 15), variable=self.sequence1_var, value='Резервоар 1')
  127. self.sequence1_rb1.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.31)
  128. self.sequence1_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15), variable=self.sequence1_var, value='Резервоар 2')
  129. self.sequence1_rb2.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.24)
  130.  
  131. # separator
  132. self.separator_frame = Frame(root, bg="black", width=2, height=122)
  133. self.separator_frame.place(x=1590, y=780)
  134.  
  135. # create a label and two radio buttons for the second sequence option
  136. self.sequence2_label = tk.Label(root, text='ДВЕ', font=('Arial', 20), bg=self.background_color, fg="black")
  137. self.sequence2_label.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.4)
  138.  
  139. self.sequence2_var = tk.StringVar(root)
  140. self.sequence2_var.set('Резервоар 2')
  141.  
  142. self.sequence2_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color,font=('Arial', 15), variable=self.sequence1_var, value='Резервоар 1')
  143. self.sequence2_rb1.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.31)
  144. self.sequence2_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15), variable=self.sequence1_var, value='Резервоар 2')
  145. self.sequence2_rb2.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.24)
  146.  
  147. # start and stop button
  148.  
  149. self.start = Button(root, text="СТАРТИРАЙ", font=('Arial', 25), bg="#41be87", fg="white")
  150. self.start.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 1.15)
  151.  
  152. self.stop = Button(root, text="СПРИ", font=('Arial', 25), bg="#e2651d", fg="white")
  153. self.stop.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 1.15)
  154.  
  155. # --------------------------------Canvas-------------------------------
  156. # canvas setup
  157. self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
  158. bg=self.background_color)
  159. self.canvas.pack()
  160. self.canvas.place(bordermode=OUTSIDE)
  161.  
  162. # heading
  163. self.canvas.create_text(self.screen_width / 3, self.screen_height / 18, text='C O N T R O L P A N E L',
  164. fill='black', font='Arial 25')
  165.  
  166. # create scale tank One
  167. self.canvas.create_line(65, 140, 65, 520, width=2)
  168. for i in range(6):
  169. self.p1 = 100 - i * 20
  170. self.y1 = 140
  171. self.y1 = self.y1 + i * 76
  172. print(self.y1)
  173. self.canvas.create_text(25, self.y1, text=self.p1, font=("Arial", 13, "bold"))
  174. self.canvas.create_text(45, self.y1, text="%", font=("Arial", 13, "bold"))
  175. self.canvas.create_line(65, self.y1, 75, self.y1, width=2)
  176.  
  177. # create scale tank Two
  178. self.canvas.create_line(65, 600, 65, 980, width=2)
  179. for i in range(6):
  180. self.p = 100 - i * 20
  181. self.y = 600
  182. self.y = self.y + i * 76
  183. self.canvas.create_text(25, self.y, text=self.p, font=("Arial", 13, "bold"))
  184. self.canvas.create_text(45, self.y, text=" %", font=("Arial", 13, "bold"))
  185. self.canvas.create_line(65, self.y, 75, self.y, width=2)
  186.  
  187. # tank One
  188. self.canvas.create_rectangle(80, 140, 360, 520, fill='#d9dddc')
  189. # tank One Water
  190. self.waterOne = self.canvas.create_rectangle(80, 140, 360, 520, fill='blue')
  191. #update_water()
  192.  
  193. # tank Two
  194. self.canvas.create_rectangle(80, 600, 360, 980, fill='#d9dddc')
  195. # tank Two Water
  196. # self.waterTwo = self.canvas.create_rectangle(80, 600, 360, 9, fill='blue')
  197.  
  198. def Exit_btn_func(self):
  199. self.Exit_btn = Exit().exit()
  200. if self.Exit_btn > 0:
  201. self.window.destroy()
  202. return
  203.  
  204. def check_condition_water_tank_one(self):
  205. if self.sum == 1:
  206. return 444
  207. elif self.sum == 2:
  208. return 368
  209. elif self.sum == 3:
  210. return 292
  211. elif self.sum == 4:
  212. return 216
  213. elif self.sum == 5:
  214. return 140
  215. else:
  216. return 515
  217.  
  218.  
  219. def update_water(self):
  220. #self.one = GPIO.input(29)
  221. #self.two = GPIO.input(31)
  222. #self.three = GPIO.input(33)
  223. #self.four = GPIO.input(35)
  224. #self.five = GPIO.input(37)
  225. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  226.  
  227. self.y1 = self.check_condition_water_tank_one()
  228. self.canvas.coords(self.waterOne, 80, self.y1, 360, 520)
  229.  
  230. self.window.after(1000, self.update_water)
  231.  
  232.  
  233. def pump_one_on_func(self):
  234. PumpOneOn()
  235.  
  236. def pump_one_off_func(self):
  237. PumpOneOff()
  238.  
  239. def pump_two_on_func(self):
  240. PumpTwoOn()
  241.  
  242. def pump_two_off_func(self):
  243. PumpTwoOff()
  244.  
  245. def auto_func(self):
  246. PumpAuto()
  247.  
  248.  
  249.  
  250. if __name__ == "__main__":
  251. root = tk.Tk()
  252. obj = Window(root)
  253. obj.update_water()
  254. root.mainloop()
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement