Advertisement
Vasilena

Diplomna_Gotova

Apr 4th, 2023 (edited)
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.84 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. class Window:
  24.    
  25.     def __init__(self, root):
  26.         # --------------------------------TK-------------------------------
  27.         # root setup
  28.         self.window = root
  29.         self.background_color = '#999da0'
  30.         self.window.attributes('-fullscreen', True)
  31.         self.window.title("Control Panel")
  32.         self.window.configure(background='#999da0')
  33.        
  34.         #root geometry
  35.         self.screen_width = self.window.winfo_screenwidth()  # 1920
  36.         self.screen_height = self.window.winfo_screenheight()  # 1080
  37.    
  38.         # manual mode
  39.         self.manual = Label(root, text="РЪЧНО УПРАВЛЕНИЕ", font=('Arial', 30), bg=self.background_color, fg="black")
  40.         self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 20)
  41.        
  42.         self.pumpOne = Label(root, text="ПОМПА 1", font=('Arial', 20), bg=self.background_color, fg="black")
  43.         self.pumpOne.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 8)
  44.        
  45.         self.pumpTwo = Label(root, text="ПОМПА 2", font=('Arial', 20), bg=self.background_color, fg="black")
  46.         self.pumpTwo.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 8)
  47.  
  48.         # buttons
  49.         self.pump_one_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_on_func,
  50.                                       bg="#198FF5", fg="white")
  51.         self.pump_one_on_btn.place(x=(self.screen_width / 3) * 2.18, y=self.screen_height / 5.8)
  52.         self.pump_one_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_off_func,
  53.                                        bg="#696969", fg="white")
  54.         self.pump_one_off_btn.place(x=(self.screen_width / 3) * 2.16, y=self.screen_height / 4.5)
  55.  
  56.         # separator
  57.         self.separator_frame = Frame(root, bg="black", width=2, height=150)
  58.         self.separator_frame.place(x=1590, y=137)
  59.  
  60.         self.pump_two_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_on_func,
  61.                                       bg="#198FF5", fg="white")
  62.         self.pump_two_on_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 5.8)
  63.         self.pump_two_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
  64.                                        bg="#696969", fg="white")
  65.         self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 4.5)
  66.        
  67.         # draning
  68.         self.manual = Label(root, text="ГЛАВЕН РЕЗЕРВОАР", font=('Arial', 30), bg=self.background_color, fg="black")
  69.         self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 3.3)
  70.        
  71.         self.pump_two_off_btn = Button(root, text="ИЗТОЧВАНЕ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
  72.                                        bg="#F06B5D", fg="white")
  73.         self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.35, y=self.screen_height / 2.7)
  74.        
  75.         # separator
  76.         self.separator_frame = Frame(root, bg="black", width=470, height=2)
  77.         self.separator_frame.place(x=1360, y=480)
  78.  
  79.         # exit program button
  80.         self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
  81.                                command=self.Exit_btn_func, bg="#EF4324", fg="white")
  82.         self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
  83.  
  84.         # automatic mode
  85.         self.automatic = Label(root, text="АВТОМАТИЧНО УПРАВЛЕНИЕ", font=('Arial', 25), bg=self.background_color, fg="black")
  86.         self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
  87.        
  88.         self.tankOne = Label(root, text="РЕЗЕРВОАР 1", font=('Arial', 20), bg=self.background_color, fg="black")
  89.         self.tankOne.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.9)
  90.        
  91.         # separator
  92.         self.separator_frame = Frame(root, bg="black", width=2, height=115)
  93.         self.separator_frame.place(x=1590, y=570)
  94.        
  95.         self.tankTwo = Label(root, text="РЕЗЕРВОАР 2", font=('Arial', 20), bg=self.background_color, fg="black")
  96.         self.tankTwo.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.9)
  97.        
  98.         # dropdown menus
  99.         self.tank1_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  100.         self.tank1_label.place(x=(self.screen_width / 3) * 2.17, y = self.screen_height / 1.7)
  101.         self.tank1_value_inside = tk.StringVar(value="0%")
  102.         self.tank1_options = ["0%", "20%", "40%", "60%", "100%"]
  103.         self.tank1_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank1_options)
  104.         self.tank1_dropdown.place(x=(self.screen_width / 3) * 2.32, y = self.screen_height / 1.7)
  105.        
  106.         # dropdown menus
  107.         self.tank2_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  108.         self.tank2_label.place(x=(self.screen_width / 3) * 2.55, y = self.screen_height / 1.7)
  109.         self.tank2_value_inside = tk.StringVar(value="0%")
  110.         self.tank2_options = ["0%", "20%", "40%", "60%", "100%"]
  111.         self.tank2_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank2_options)
  112.         self.tank2_dropdown.place(x=(self.screen_width / 3) * 2.70, y = self.screen_height / 1.7)
  113.        
  114.         # order choice
  115.         self.automatic = Label(root, text="ИЗБЕРИ ПОСЛЕДОВАТЕЛНОСТ9d ", font=('Arial', 25), bg=self.background_color, fg="black")
  116.         self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
  117.  
  118.         #self.automatic_btn = Button(root, text="AUTOMATIC MODE", font=('Arial', 15), command=self.auto_func,
  119.                                     #bg="white", fg="black")
  120.         #self.automatic_btn.place(x=(self.screen_width / 3) * 2, y=self.screen_height / 8)
  121.  
  122.          # --------------------------------Canvas-------------------------------
  123.         # canvas setup
  124.         self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
  125.                              bg=self.background_color)
  126.         self.canvas.pack()
  127.         self.canvas.place(bordermode=OUTSIDE)
  128.  
  129.         # heading
  130.         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',
  131.                                 fill='black', font='Arial 25')
  132.  
  133.         # create scale tank One
  134.         self.canvas.create_line(40, 110, 40, 370, width=2)
  135.         for i in range(6):
  136.             self.p1 = 100 - i * 20
  137.             self.y1 = 110
  138.             self.y1 = self.y1 + i * 52
  139.             self.canvas.create_text(15, self.y1, text=self.p1, font=("Arial", 10, "bold"))
  140.             self.canvas.create_text(30, self.y1, text="%", font=("Arial", 10, "bold"))
  141.             self.canvas.create_line(40, self.y1, 50, self.y1, width=2)
  142.  
  143.         # create scale tank Two
  144.         self.canvas.create_line(40, 450, 40, 710, width=2)
  145.         for i in range(6):
  146.             self.p = 100 - i * 20
  147.             self.y = 450
  148.             self.y = self.y + i * 52
  149.             self.canvas.create_text(15, self.y, text=self.p, font=("Arial", 10, "bold"))
  150.             self.canvas.create_text(30, self.y, text="%", font=("Arial", 10, "bold"))
  151.             self.canvas.create_line(40, self.y, 50, self.y, width=2)
  152.  
  153.         # tank One
  154.         self.canvas.create_rectangle(60, 110, 230, 370, fill='#d9dddc')
  155.         # tank One Water
  156.         self.waterOne = self.canvas.create_rectangle(60, 365, 230, 370, fill='blue')
  157.         #update_water()
  158.        
  159.         # tank Two
  160.         self.canvas.create_rectangle(60, 450, 230, 710, fill='#d9dddc')
  161.         # tank Two Water
  162.         self.waterTwo = self.canvas.create_rectangle(60, 505, 230, 710, fill='blue')
  163.            
  164.     def Exit_btn_func(self):
  165.         self.Exit_btn = Exit().exit()
  166.         if self.Exit_btn > 0:
  167.             self.window.destroy()
  168.             return
  169.                
  170.     def check_condition_water_tank_one(self):
  171.         if self.sum == 1:
  172.             return 318
  173.         elif self.sum == 2:
  174.             return 266
  175.         elif self.sum == 3:
  176.             return 214
  177.         elif self.sum == 4:
  178.             return 162
  179.         elif self.sum == 5:
  180.             return 115
  181.         else:
  182.             return 365    
  183.        
  184.    
  185.     def update_water(self):
  186.         #self.one = GPIO.input(29)
  187.         #self.two = GPIO.input(31)
  188.         #self.three = GPIO.input(33)
  189.         #self.four = GPIO.input(35)
  190.         #self.five = GPIO.input(37)
  191.         self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  192.  
  193.         self.y1 = self.check_condition_water_tank_one()
  194.         self.canvas.coords(self.waterOne, 60, self.y1, 230, 370)
  195.  
  196.         self.window.after(1000, self.update_water)
  197.  
  198.  
  199.     def pump_one_on_func(self):
  200.         PumpOneOn()
  201.  
  202.     def pump_one_off_func(self):
  203.         PumpOneOff()
  204.  
  205.     def pump_two_on_func(self):
  206.         PumpTwoOn()
  207.  
  208.     def pump_two_off_func(self):
  209.         PumpTwoOff()
  210.  
  211.     def auto_func(self):
  212.         PumpAuto()
  213.        
  214.  
  215.  
  216. if __name__ == "__main__":
  217.     root = tk.Tk()
  218.     obj = Window(root)
  219.     obj.update_water()
  220.     root.mainloop()
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement