Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import *
- from tkinter import ttk
- from tkinter import messagebox
- import tkinter.messagebox
- from pump_two_on import PumpTwoOn
- from pump_two_off import PumpTwoOff
- from pump_one_on import PumpOneOn
- from pump_one_off import PumpOneOff
- from auto import PumpAuto
- from exit import Exit
- import RPi.GPIO as GPIO
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(29, GPIO.IN)
- GPIO.setup(31, GPIO.IN)
- GPIO.setup(33, GPIO.IN)
- GPIO.setup(35, GPIO.IN)
- GPIO.setup(37, GPIO.IN)
- class Window:
- def __init__(self, root):
- # --------------------------------TK-------------------------------
- # root setup
- self.window = root
- self.background_color = '#999da0'
- self.window.attributes('-fullscreen', True)
- self.window.title("Control Panel")
- self.window.configure(background='#999da0')
- #root geometry
- self.screen_width = self.window.winfo_screenwidth() # 1920
- self.screen_height = self.window.winfo_screenheight() # 1080
- # manual mode
- self.manual = Label(root, text="РЪЧНО УПРАВЛЕНИЕ", font=('Arial', 30), bg=self.background_color, fg="black")
- self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 20)
- self.pumpOne = Label(root, text="ПОМПА 1", font=('Arial', 20), bg=self.background_color, fg="black")
- self.pumpOne.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 8)
- self.pumpTwo = Label(root, text="ПОМПА 2", font=('Arial', 20), bg=self.background_color, fg="black")
- self.pumpTwo.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 8)
- # buttons
- self.pump_one_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_on_func,
- bg="#198FF5", fg="white")
- self.pump_one_on_btn.place(x=(self.screen_width / 3) * 2.18, y=self.screen_height / 5.8)
- self.pump_one_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_off_func,
- bg="#696969", fg="white")
- self.pump_one_off_btn.place(x=(self.screen_width / 3) * 2.16, y=self.screen_height / 4.5)
- # separator
- self.separator_frame = Frame(root, bg="black", width=2, height=150)
- self.separator_frame.place(x=1590, y=137)
- self.pump_two_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_on_func,
- bg="#198FF5", fg="white")
- self.pump_two_on_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 5.8)
- self.pump_two_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
- bg="#696969", fg="white")
- self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 4.5)
- # draning
- self.manual = Label(root, text="ГЛАВЕН РЕЗЕРВОАР", font=('Arial', 30), bg=self.background_color, fg="black")
- self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 3.3)
- self.pump_two_off_btn = Button(root, text="ИЗТОЧВАНЕ", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
- bg="#F06B5D", fg="white")
- self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.35, y=self.screen_height / 2.7)
- # separator
- self.separator_frame = Frame(root, bg="black", width=470, height=2)
- self.separator_frame.place(x=1360, y=480)
- # exit program button
- self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
- command=self.Exit_btn_func, bg="#EF4324", fg="white")
- self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
- # automatic mode
- self.automatic = Label(root, text="АВТОМАТИЧНО УПРАВЛЕНИЕ", font=('Arial', 25), bg=self.background_color, fg="black")
- self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
- self.tankOne = Label(root, text="РЕЗЕРВОАР 1", font=('Arial', 20), bg=self.background_color, fg="black")
- self.tankOne.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.9)
- # separator
- self.separator_frame = Frame(root, bg="black", width=2, height=115)
- self.separator_frame.place(x=1590, y=570)
- self.tankTwo = Label(root, text="РЕЗЕРВОАР 2", font=('Arial', 20), bg=self.background_color, fg="black")
- self.tankTwo.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.9)
- # dropdown menus
- self.tank1_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
- self.tank1_label.place(x=(self.screen_width / 3) * 2.17, y = self.screen_height / 1.7)
- self.tank1_value_inside = tk.StringVar(value="0%")
- self.tank1_options = ["0%", "20%", "40%", "60%", "100%"]
- self.tank1_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank1_options)
- self.tank1_dropdown.place(x=(self.screen_width / 3) * 2.32, y = self.screen_height / 1.7)
- # dropdown menus
- self.tank2_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
- self.tank2_label.place(x=(self.screen_width / 3) * 2.55, y = self.screen_height / 1.7)
- self.tank2_value_inside = tk.StringVar(value="0%")
- self.tank2_options = ["0%", "20%", "40%", "60%", "100%"]
- self.tank2_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank2_options)
- self.tank2_dropdown.place(x=(self.screen_width / 3) * 2.70, y = self.screen_height / 1.7)
- # order choice
- self.automatic = Label(root, text="ИЗБЕРИ ПОСЛЕДОВАТЕЛНОСТ9d ", font=('Arial', 25), bg=self.background_color, fg="black")
- self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
- #self.automatic_btn = Button(root, text="AUTOMATIC MODE", font=('Arial', 15), command=self.auto_func,
- #bg="white", fg="black")
- #self.automatic_btn.place(x=(self.screen_width / 3) * 2, y=self.screen_height / 8)
- # --------------------------------Canvas-------------------------------
- # canvas setup
- self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
- bg=self.background_color)
- self.canvas.pack()
- self.canvas.place(bordermode=OUTSIDE)
- # heading
- 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',
- fill='black', font='Arial 25')
- # create scale tank One
- self.canvas.create_line(40, 110, 40, 370, width=2)
- for i in range(6):
- self.p1 = 100 - i * 20
- self.y1 = 110
- self.y1 = self.y1 + i * 52
- self.canvas.create_text(15, self.y1, text=self.p1, font=("Arial", 10, "bold"))
- self.canvas.create_text(30, self.y1, text="%", font=("Arial", 10, "bold"))
- self.canvas.create_line(40, self.y1, 50, self.y1, width=2)
- # create scale tank Two
- self.canvas.create_line(40, 450, 40, 710, width=2)
- for i in range(6):
- self.p = 100 - i * 20
- self.y = 450
- self.y = self.y + i * 52
- self.canvas.create_text(15, self.y, text=self.p, font=("Arial", 10, "bold"))
- self.canvas.create_text(30, self.y, text="%", font=("Arial", 10, "bold"))
- self.canvas.create_line(40, self.y, 50, self.y, width=2)
- # tank One
- self.canvas.create_rectangle(60, 110, 230, 370, fill='#d9dddc')
- # tank One Water
- self.waterOne = self.canvas.create_rectangle(60, 365, 230, 370, fill='blue')
- #update_water()
- # tank Two
- self.canvas.create_rectangle(60, 450, 230, 710, fill='#d9dddc')
- # tank Two Water
- self.waterTwo = self.canvas.create_rectangle(60, 505, 230, 710, fill='blue')
- def Exit_btn_func(self):
- self.Exit_btn = Exit().exit()
- if self.Exit_btn > 0:
- self.window.destroy()
- return
- def check_condition_water_tank_one(self):
- if self.sum == 1:
- return 318
- elif self.sum == 2:
- return 266
- elif self.sum == 3:
- return 214
- elif self.sum == 4:
- return 162
- elif self.sum == 5:
- return 115
- else:
- return 365
- def update_water(self):
- #self.one = GPIO.input(29)
- #self.two = GPIO.input(31)
- #self.three = GPIO.input(33)
- #self.four = GPIO.input(35)
- #self.five = GPIO.input(37)
- self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
- self.y1 = self.check_condition_water_tank_one()
- self.canvas.coords(self.waterOne, 60, self.y1, 230, 370)
- self.window.after(1000, self.update_water)
- def pump_one_on_func(self):
- PumpOneOn()
- def pump_one_off_func(self):
- PumpOneOff()
- def pump_two_on_func(self):
- PumpTwoOn()
- def pump_two_off_func(self):
- PumpTwoOff()
- def auto_func(self):
- PumpAuto()
- if __name__ == "__main__":
- root = tk.Tk()
- obj = Window(root)
- obj.update_water()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement