Advertisement
Vasilena

gui

Mar 30th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import *
  3. import RPi.GPIO as GPIO
  4. from time import sleep
  5.  
  6.  
  7. def close():
  8. root.destroy()
  9.  
  10. GPIO.setwarnings(False)
  11. GPIO.setmode(GPIO.BOARD)
  12.  
  13. # GPOI SETUP
  14. PUMP_ONE_PIN = 38;
  15. PUMP_TWO_PIN = 40;
  16. GPIO.setup(PUMP_ONE_PIN, GPIO.OUT)
  17. GPIO.setup(PUMP_TWO_PIN, GPIO.OUT)
  18.  
  19. def pump_on(pumpPin):
  20. GPIO.output(pumpPin, GPIO.HIGH)
  21.  
  22. def pump_off(pumpPin):
  23. GPIO.output(pumpPin, GPIO.LOW)
  24.  
  25. # root setup
  26. background_color = '#999da0'
  27. root = tk.Tk()
  28. root.attributes('-fullscreen', True)
  29. root.title("Control Panel")
  30. root.configure(background='#999da0')
  31.  
  32. screen_width = root.winfo_screenwidth() #1920
  33. screen_height = root.winfo_screenheight() #1080
  34.  
  35. # manual mode
  36. manual = Label(root, text="MANUAL MODE", font=('Arial', 15), bg=background_color, fg="black")
  37. manual.place(x=(screen_width/3)*2, y=screen_height/10)
  38.  
  39. pump_one_on_btn = Button(root, text="1 ON", font=("Arial", 15, "bold"), command=lambda: pump_on(PUMP_ONE_PIN), bg="red", fg="white")
  40. pump_one_on_btn.place(x=1300, y=200)
  41. pump_one_off_btn = Button(root, text="1 OFF", font=("Arial", 15, "bold"), command=lambda: pump_off(PUMP_ONE_PIN), bg="red", fg="white")
  42. pump_one_off_btn.place(x=1300, y=250)
  43.  
  44. pump_two_on_btn = Button(root, text="2 ON", font=("Arial", 15, "bold"), command=lambda: pump_on(PUMP_TWO_PIN), bg="red", fg="white")
  45. pump_two_on_btn.place(x=1800, y=200)
  46. pump_two_off_btn = Button(root, text="2 OFF", font=("Arial", 15, "bold"), command=lambda: pump_off(PUMP_TWO_PIN), bg="red", fg="white")
  47. pump_two_off_btn.place(x=1800, y=250)
  48.  
  49. # exit program button
  50. exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"), command=close, bg="red", fg="white")
  51. exit_btn.place(x=screen_width-55, y = screen_height-(screen_height-5))
  52.  
  53. # automatic mode
  54. automatic_btn = Button(root, text="AUTOMATIC MODE", font=('Arial', 15), bg="white", fg="black")
  55. automatic_btn.place(x=(screen_width/3)*2, y=screen_height/8)
  56.  
  57. # canvas setup
  58. canvas = Canvas(root, width=(screen_width/3)*2, height=screen_height, bg=background_color)
  59. canvas.pack()
  60. canvas.place(bordermode=OUTSIDE)
  61.  
  62. # heading
  63. canvas.create_text(screen_width/3, screen_height/18, text='C O N T R O L P A N E L', fill='black', font='Arial 25')
  64.  
  65. # create scale tank One
  66. canvas.create_line(40, 110, 40, 370, width=2)
  67. for i in range(6):
  68. p = 100 - i * 20
  69. y = 110
  70. y = y + i*52
  71. canvas.create_text(15, y, text=p, font=("Arial", 10, "bold"))
  72. canvas.create_text(30, y, text="%", font=("Arial", 10, "bold"))
  73. canvas.create_line(40, y, 50, y, width=2)
  74.  
  75. # create scale tank Two
  76. canvas.create_line(40, 450, 40, 710, width=2)
  77. for i in range(6):
  78. p = 100-i*20
  79. y = 450
  80. y = y + i * 52
  81. canvas.create_text(15, y, text=p, font=("Arial", 10, "bold"))
  82. canvas.create_text(30, y, text="%", font=("Arial", 10, "bold"))
  83. canvas.create_line(40, y, 50, y, width=2)
  84.  
  85. # tank One
  86. canvas.create_rectangle(60, 110, 230, 370, fill='#d9dddc')
  87. # tank One Water
  88. canvas.create_rectangle(60, 240, 230, 370, fill='blue')
  89.  
  90. # tank Two
  91. canvas.create_rectangle(60, 450, 230, 710, fill='#d9dddc')
  92. # tank Two Water
  93. canvas.create_rectangle(60, 505, 230, 710, fill='blue')
  94.  
  95. # pumpOne
  96. root.mainloop()
  97.  
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement