Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import cv2
- from PIL import Image
- from PIL import ImageTk
- root = Tk()
- root.wm_title("Дипломна работа")
- is_on = False
- def mode_button_function():
- global is_on
- if is_on:
- is_on = False
- b1.config(activebackground='green')
- b2.config(activebackground='green')
- b3.config(activebackground='green')
- b4.config(activebackground='green')
- mode_label.config(text='Automatic mode = Off')
- mode_button.config(text='OFF', bg='red')
- else:
- is_on = True
- b1.config(activebackground='white')
- b2.config(activebackground='white')
- b3.config(activebackground='white')
- b4.config(activebackground='white')
- mode_label.config(text='Automatic mode = On')
- mode_button.config(text='ON', bg='green')
- def upButton():
- global is_on
- if not is_on:
- print('forward')
- def downButton():
- global is_on
- if not is_on:
- print('backward')
- def leftButton():
- global is_on
- if not is_on:
- print('left')
- def rightButton():
- global is_on
- if not is_on:
- print('right')
- imageFrame = Frame(root)
- imageFrame.grid(row=0, column=4, rowspan=5)
- cap = cv2.VideoCapture(2)
- def show_frame():
- _, frame = cap.read()
- frame = cv2.flip(frame, 1)
- cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
- img = Image.fromarray(cv2image)
- imgtk = ImageTk.PhotoImage(image=img)
- display1.imgtk = imgtk # Shows frame for display 1
- display1.configure(image=imgtk)
- root.after(10, show_frame)
- display1 = Label(imageFrame)
- display1.grid(row=0, column=0, rowspan=5) # Display 1
- b1 = Button(root, text='^', padx=25, pady=25, command=upButton, background='white', activebackground='green')
- b2 = Button(root, text='<', padx=25, pady=25, command=leftButton, background='white', activebackground='green')
- b3 = Button(root, text='>', padx=25, pady=25, command=rightButton, background='white', activebackground='green')
- b4 = Button(root, text='v', padx=25, pady=25, command=downButton, background='white', activebackground='green')
- mode_label = Label(root, text='Automatic mode = Off', padx=15, pady=15)
- mode_button = Button(root, text='OFF', padx=15, pady=15, bg='red', command=mode_button_function)
- b1.grid(row=0, column=1)
- b2.grid(row=1, column=0)
- b3.grid(row=1, column=2)
- b4.grid(row=2, column=1)
- mode_label.grid(row=3, column=0, columnspan=3)
- mode_button.grid(row=4, column=1)
- show_frame()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment