Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import *
- 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 senzor import senzor
- from auto import PumpAuto
- from exit import Exit
- import RPi.GPIO as GPIO
- GPIO.setmode(GPIO.BOARD)
- GPIO.setwarnings(False)
- 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):
- self.window = root
- self.background_color = '#999da0'
- self.window.attributes('-fullscreen', True)
- self.window.title("Control Panel")
- self.window.configure(background='#999da0')
- self.screen_width = self.window.winfo_screenwidth() # 1920
- self.screen_height = self.window.winfo_screenheight() # 1080
- # manual mode
- self.manual = Label(root, text="MANUAL MODE", font=('Arial', 15), bg=self.background_color, fg="black")
- self.manual.place(x=(self.screen_width / 3) * 2, y=self.screen_height / 10)
- # buttons
- self.pump_one_on_btn = Button(root, text="1 ON", font=("Arial", 15, "bold"), command=self.pump_one_on_func,
- bg="red", fg="white")
- self.pump_one_on_btn.place(x=1300, y=200)
- self.pump_one_off_btn = Button(root, text="1 OFF", font=("Arial", 15, "bold"), command=self.pump_one_off_func,
- bg="red", fg="white")
- self.pump_one_off_btn.place(x=1300, y=250)
- self.pump_two_on_btn = Button(root, text="2 ON", font=("Arial", 15, "bold"),command=self.pump_two_on_func,
- bg="red", fg="white")
- self.pump_two_on_btn.place(x=1800, y=200)
- self.pump_two_off_btn = Button(root, text="2 OFF", font=("Arial", 15, "bold"),command=self.pump_two_off_func,
- bg="red", fg="white")
- self.pump_two_off_btn.place(x=1800, y=250)
- # exit program button
- self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
- command=self.Exit_btn_func, bg="red", fg="white")
- self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
- # automatic mode
- 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 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
- while True:
- one = GPIO.input(29)
- two = GPIO.input(31)
- three = GPIO.input(33)
- four = GPIO.input(35)
- five = GPIO.input(37)
- self.waterOne = self.canvas.create_rectangle(60, check_condition_water_tank_one(one, two, three, four, five), 230, 370, fill='blue')
- # tank Two
- self.rect2 = self.canvas.create_rectangle(60, 450, 230, 710, fill='#d9dddc')
- # tank Two Water
- self.watetTwo = self.canvas.create_rectangle(60, 505, 230, 710, fill='blue')
- def check_condition_water_tank_one(one, two, three, four, five):
- if one == 1 and two == 0 and three == 0 and four == 0 and five == 0:
- return 318
- elif one == 1 and two == 1 and three == 0 and four == 0 and five == 0:
- return 266
- elif one == 1 and two == 1 and three == 1 and four == 0 and five == 0:
- return 214
- elif one == 1 and two == 1 and three == 1 and four == 1 and five == 0:
- return 162
- elif one == 1 and two == 1 and three == 1 and four == 1 and five == 1:
- return 115
- else:
- return 365
- def Exit_btn_func(self):
- self.Exit_btn = Exit().exit()
- if self.Exit_btn > 0:
- self.window.destroy()
- return
- 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()
- def senzor_func(self):
- senzor()
- if __name__ == "__main__":
- root = tk.Tk()
- obj = Window(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement