Advertisement
Vasilena

diplomna_NOV

Apr 3rd, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import *
  3. from tkinter import messagebox
  4. import tkinter.messagebox
  5. from pump_two_on import PumpTwoOn
  6. from pump_two_off import PumpTwoOff
  7. from pump_one_on import PumpOneOn
  8. from pump_one_off import PumpOneOff
  9. from senzor import senzor
  10. from auto import PumpAuto
  11. from exit import Exit
  12. import RPi.GPIO as GPIO
  13.  
  14. GPIO.setmode(GPIO.BOARD)
  15. GPIO.setwarnings(False)
  16. GPIO.setup(29, GPIO.IN)
  17. GPIO.setup(31, GPIO.IN)
  18. GPIO.setup(33, GPIO.IN)
  19. GPIO.setup(35, GPIO.IN)
  20. GPIO.setup(37, GPIO.IN)
  21.  
  22. class Window:
  23.  
  24. def __init__(self, root):
  25. self.window = root
  26. self.background_color = '#999da0'
  27. self.window.attributes('-fullscreen', True)
  28. self.window.title("Control Panel")
  29. self.window.configure(background='#999da0')
  30.  
  31. self.screen_width = self.window.winfo_screenwidth() # 1920
  32. self.screen_height = self.window.winfo_screenheight() # 1080
  33.  
  34. # manual mode
  35. self.manual = Label(root, text="MANUAL MODE", font=('Arial', 15), bg=self.background_color, fg="black")
  36. self.manual.place(x=(self.screen_width / 3) * 2, y=self.screen_height / 10)
  37.  
  38. # buttons
  39. self.pump_one_on_btn = Button(root, text="1 ON", font=("Arial", 15, "bold"), command=self.pump_one_on_func,
  40. bg="red", fg="white")
  41. self.pump_one_on_btn.place(x=1300, y=200)
  42. self.pump_one_off_btn = Button(root, text="1 OFF", font=("Arial", 15, "bold"), command=self.pump_one_off_func,
  43. bg="red", fg="white")
  44. self.pump_one_off_btn.place(x=1300, y=250)
  45.  
  46. self.pump_two_on_btn = Button(root, text="2 ON", font=("Arial", 15, "bold"),command=self.pump_two_on_func,
  47. bg="red", fg="white")
  48. self.pump_two_on_btn.place(x=1800, y=200)
  49. self.pump_two_off_btn = Button(root, text="2 OFF", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
  50. bg="red", fg="white")
  51. self.pump_two_off_btn.place(x=1800, y=250)
  52.  
  53. # exit program button
  54. self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
  55. command=self.Exit_btn_func, bg="red", fg="white")
  56. self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
  57.  
  58. # automatic mode
  59. self.automatic_btn = Button(root, text="AUTOMATIC MODE", font=('Arial', 15), command=self.auto_func,
  60. bg="white", fg="black")
  61. self.automatic_btn.place(x=(self.screen_width / 3) * 2, y=self.screen_height / 8)
  62.  
  63. # canvas setup
  64. self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
  65. bg=self.background_color)
  66. self.canvas.pack()
  67. self.canvas.place(bordermode=OUTSIDE)
  68.  
  69. # heading
  70. 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',
  71. fill='black', font='Arial 25')
  72.  
  73. # create scale tank One
  74. self.canvas.create_line(40, 110, 40, 370, width=2)
  75. for i in range(6):
  76. self.p1 = 100 - i * 20
  77. self.y1 = 110
  78. self.y1 = self.y1 + i * 52
  79. self.canvas.create_text(15, self.y1, text=self.p1, font=("Arial", 10, "bold"))
  80. self.canvas.create_text(30, self.y1, text="%", font=("Arial", 10, "bold"))
  81. self.canvas.create_line(40, self.y1, 50, self.y1, width=2)
  82.  
  83. # create scale tank Two
  84. self.canvas.create_line(40, 450, 40, 710, width=2)
  85. for i in range(6):
  86. self.p = 100 - i * 20
  87. self.y = 450
  88. self.y = self.y + i * 52
  89. self.canvas.create_text(15, self.y, text=self.p, font=("Arial", 10, "bold"))
  90. self.canvas.create_text(30, self.y, text="%", font=("Arial", 10, "bold"))
  91. self.canvas.create_line(40, self.y, 50, self.y, width=2)
  92.  
  93. # tank One
  94. self.canvas.create_rectangle(60, 110, 230, 370, fill='#d9dddc')
  95. # tank One Water
  96. while True:
  97. one = GPIO.input(29)
  98. two = GPIO.input(31)
  99. three = GPIO.input(33)
  100. four = GPIO.input(35)
  101. five = GPIO.input(37)
  102. self.waterOne = self.canvas.create_rectangle(60, check_condition_water_tank_one(one, two, three, four, five), 230, 370, fill='blue')
  103.  
  104. # tank Two
  105. self.rect2 = self.canvas.create_rectangle(60, 450, 230, 710, fill='#d9dddc')
  106. # tank Two Water
  107. self.watetTwo = self.canvas.create_rectangle(60, 505, 230, 710, fill='blue')
  108.  
  109. def check_condition_water_tank_one(one, two, three, four, five):
  110. if one == 1 and two == 0 and three == 0 and four == 0 and five == 0:
  111. return 318
  112. elif one == 1 and two == 1 and three == 0 and four == 0 and five == 0:
  113. return 266
  114. elif one == 1 and two == 1 and three == 1 and four == 0 and five == 0:
  115. return 214
  116. elif one == 1 and two == 1 and three == 1 and four == 1 and five == 0:
  117. return 162
  118. elif one == 1 and two == 1 and three == 1 and four == 1 and five == 1:
  119. return 115
  120. else:
  121. return 365
  122.  
  123.  
  124. def Exit_btn_func(self):
  125. self.Exit_btn = Exit().exit()
  126. if self.Exit_btn > 0:
  127. self.window.destroy()
  128. return
  129.  
  130. def pump_one_on_func(self):
  131. PumpOneOn()
  132.  
  133. def pump_one_off_func(self):
  134. PumpOneOff()
  135.  
  136. def pump_two_on_func(self):
  137. PumpTwoOn()
  138.  
  139. def pump_two_off_func(self):
  140. PumpTwoOff()
  141.  
  142. def auto_func(self):
  143. PumpAuto()
  144.  
  145. def senzor_func(self):
  146. senzor()
  147.  
  148.  
  149. if __name__ == "__main__":
  150. root = tk.Tk()
  151. obj = Window(root)
  152. root.mainloop()
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement