Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Tkinter Script to Display Webcam Video Using tkinter-webcam Library in Window GUI Desktop App Full Project For Beginners

Posted on October 26, 2022

 

 

Welcome folks today in this blog post we will be displaying the webcam video in tkinter window using the tkinter-webcam library. This will a GUI Desktop Application built using the tkinter framework. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

In order to get started you need to install the below library of tkinter to display webcam video. You can install the library using the pip command as shown below

 

pip install tkinter-webcam

 

 

After installing it you need to make an app.py file and copy paste the following code

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
"""Example"""
import tkinter as tk
from tkinter_webcam import webcam
 
window = tk.Tk()  # Sets up GUI
window.title("Example")  # Titles GUI
window.geometry("1000x1000")  # Sizes GUI
 
# Uses Box class from webcam to create video window
video = webcam.Box(window, width=450, height=450)
video.show_frames()  # Show the created Box
 
tk.mainloop()

 

 

Code Explanation

 

 

As you can see in the first line of code we are importing the tkinter webcam package and also we are importing the base tkinter library as well.

 

 

Python
1
2
import tkinter as tk
from tkinter_webcam import webcam

 

 

And then we are initializing a new tkinter window of width and height using the geometry method as shown below

 

 

Python
1
2
3
window = tk.Tk()  # Sets up GUI
window.title("Example")  # Titles GUI
window.geometry("1000x1000")  # Sizes GUI

 

 

And then we are using the webcam.Box() method to display the user webcam video using the built in webcam of the user device. And inside this function we are passing the tkinter window as the first argument and then we are passing the width and height of the webcam video as the second and third argument.

 

And then guys we are showing the webcam video frames inside the tkinter window

 

 

Python
1
2
3
# Uses Box class from webcam to create video window
video = webcam.Box(window, width=450, height=450)
video.show_frames()  # Show the created Box

 

 

As you can see we are using the Box class of the webcam module to create the actual webcam video inside the tkinter window. And then we are showing it using the show_frames() method.

 

 

And now lastly we are running the tkinter app by calling the mainloop() method which is present inside the base tkinter library as shown below

 

 

Python
1
tk.mainloop()

 

 

Now if you run the app.py file by executing the below command as shown below

 

 

python app.py

 

 

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme