Zeshin

GUI

Apr 4th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. from tkinter import *
  2. import cv2
  3. from PIL import Image
  4. from PIL import ImageTk
  5.  
  6. root = Tk()
  7. root.wm_title("Дипломна работа")
  8.  
  9. is_on = False
  10.  
  11.  
  12. def mode_button_function():
  13. global is_on
  14. if is_on:
  15. is_on = False
  16. b1.config(activebackground='green')
  17. b2.config(activebackground='green')
  18. b3.config(activebackground='green')
  19. b4.config(activebackground='green')
  20. mode_label.config(text='Automatic mode = Off')
  21. mode_button.config(text='OFF', bg='red')
  22. else:
  23. is_on = True
  24. b1.config(activebackground='white')
  25. b2.config(activebackground='white')
  26. b3.config(activebackground='white')
  27. b4.config(activebackground='white')
  28. mode_label.config(text='Automatic mode = On')
  29. mode_button.config(text='ON', bg='green')
  30.  
  31.  
  32. def upButton():
  33. global is_on
  34. if not is_on:
  35. print('forward')
  36.  
  37.  
  38. def downButton():
  39. global is_on
  40. if not is_on:
  41. print('backward')
  42.  
  43.  
  44. def leftButton():
  45. global is_on
  46. if not is_on:
  47. print('left')
  48.  
  49.  
  50. def rightButton():
  51. global is_on
  52. if not is_on:
  53. print('right')
  54.  
  55.  
  56. imageFrame = Frame(root)
  57. imageFrame.grid(row=0, column=4, rowspan=5)
  58. cap = cv2.VideoCapture(2)
  59.  
  60.  
  61. def show_frame():
  62. _, frame = cap.read()
  63. frame = cv2.flip(frame, 1)
  64. cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
  65. img = Image.fromarray(cv2image)
  66. imgtk = ImageTk.PhotoImage(image=img)
  67. display1.imgtk = imgtk # Shows frame for display 1
  68. display1.configure(image=imgtk)
  69. root.after(10, show_frame)
  70.  
  71.  
  72. display1 = Label(imageFrame)
  73. display1.grid(row=0, column=0, rowspan=5) # Display 1
  74. b1 = Button(root, text='^', padx=25, pady=25, command=upButton, background='white', activebackground='green')
  75. b2 = Button(root, text='<', padx=25, pady=25, command=leftButton, background='white', activebackground='green')
  76. b3 = Button(root, text='>', padx=25, pady=25, command=rightButton, background='white', activebackground='green')
  77. b4 = Button(root, text='v', padx=25, pady=25, command=downButton, background='white', activebackground='green')
  78. mode_label = Label(root, text='Automatic mode = Off', padx=15, pady=15)
  79. mode_button = Button(root, text='OFF', padx=15, pady=15, bg='red', command=mode_button_function)
  80.  
  81. b1.grid(row=0, column=1)
  82. b2.grid(row=1, column=0)
  83. b3.grid(row=1, column=2)
  84. b4.grid(row=2, column=1)
  85. mode_label.grid(row=3, column=0, columnspan=3)
  86. mode_button.grid(row=4, column=1)
  87.  
  88. show_frame()
  89. root.mainloop()
  90.  
Advertisement
Add Comment
Please, Sign In to add comment