Python Forum
tkinter frame camera opencv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter frame camera opencv
#1
Hello.I have a main window using tkinter.I call a function that has:
root.after(1 , camera_status , ....) and other things
So,in camera_status which is inside in another file has:

from tkinter import *
#from GUI_camera import video_stream
import cv2 , PIL
from PIL import Image,ImageTk
cap = cv2.VideoCapture(0)

def camera_status(root , FOREGROUND_COLOR , ACTIVE_FOREGROUND_COLOR , BACKGROUND_COLOR , ACTIVE_BACKGROUND_COLOR , mode):  # control camera
    camera_frame = LabelFrame(root , width = 663 , height = 528)
    camera_frame.place(x = 844 , y = 300)
    
    if(mode):
        ret , frame = cap.read()
        if(ret):
            frame = cv2.flip(frame , 1)
            cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
            img = PIL.Image.fromarray(cv2image)
            imgtk = ImageTk.PhotoImage(image = img)
            camera_frame.imgtk = imgtk
            camera_frame.configure(image = imgtk)
    
        enable_camera_logo = Image.open("logo/enable_camera.png")
        
    else:
        enable_camera_logo = Image.open("logo/disable_camera.png")
        

    enable_camera_logo = enable_camera_logo.resize( (75 , 30) , resample = 0)
    enable_camera_image = ImageTk.PhotoImage(enable_camera_logo)

    camera_button = Button(root , highlightbackground = "black" , bd = 0 , image = enable_camera_image , activeforeground = "black", activebackground = "black" , bg = "black" , relief = SUNKEN)
    camera_button.config(command = lambda: camera_status(root , FOREGROUND_COLOR , ACTIVE_FOREGROUND_COLOR , BACKGROUND_COLOR , ACTIVE_BACKGROUND_COLOR , mode))
    camera_button.image = enable_camera_image
    camera_button.place(x = 840 , y = 250)

    mode = not mode
I just want to push a button and inside my frame(camera_frame) to enable camera.So,when I push the button ,the light from my camera (laptop) is enable ,but it doesn't show anything isnide frame.
Doyou have any idea what is going on and how can I fix it?

Don't run this code ,because I have icons for the button.
Thanks.
Reply


Messages In This Thread
tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 12:00 AM
RE: tkinter frame camera opencv - by deanhystad - Mar-21-2021, 04:07 AM
RE: tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 09:30 AM
RE: tkinter frame camera opencv - by deanhystad - Mar-21-2021, 12:54 PM
RE: tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 12:59 PM
RE: tkinter frame camera opencv - by deanhystad - Mar-21-2021, 01:13 PM
RE: tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 01:48 PM
RE: tkinter frame camera opencv - by deanhystad - Mar-21-2021, 02:05 PM
RE: tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 02:11 PM
RE: tkinter frame camera opencv - by Nick_tkinter - Mar-21-2021, 06:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,024 Jan-16-2024, 06:44 PM
Last Post: rob101
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,596 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  tkinter mapview in a frame janeik 2 1,337 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,152 Sep-30-2021, 05:57 PM
Last Post: menator01
  tkinter camera threads Nick_tkinter 6 3,444 Apr-16-2021, 12:23 PM
Last Post: Nick_tkinter
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,872 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  How to disable focus on Frame in Tkinter? szafranji 1 3,037 May-13-2020, 10:45 PM
Last Post: DT2000
  [Tkinter] Tkinter bringing variables from 1 frame to another zukochew 6 12,580 Dec-26-2019, 05:27 AM
Last Post: skm
  Unable to put background image on Tkinter Frame jenkins43 2 8,772 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,036 Sep-30-2019, 07:30 AM
Last Post: Maksim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020