Python Screen Recorder - Python Geeks
Python Screen Recorder - Python Geeks
To record our screen for presentation, we cannot rely on cameras. This is attributed
to the quality and shakiness observed whilst recording. So what is the best
alternative? A Screen Recorder. A screen recorder records the contents or anything
visible on the screen and saves it for later use. Now the advantages are plenty;
quality of the recording, less hassle and you can record it again at ease. Let us make
Python Screen Recorder Project.
Project Prerequisites
The project is an introduction to Pillow and OpenCV. Hence understanding the
syntactic meaning should suffice. The modules necessary are opencv, tkinter and
pillow. Tkinter is already available in Python. Import to see, if it is available.
1. import tkinter
If it does not show any error, the package is available. If not, you can install it using
the command
sudo apt-get install python3-tkinter, for linux users and windows users can reinstall
python or follow the steps given in Tkinter installation on windows. We can use pip
to install the other packages as follows:
OpenCV:
pillow
1. Importing libraries
2. Creating the screen recording function
3. Defining the GUI
4. Create the components and the button
1. Importing libraries:
1. #PythonGeeks Guide to create a simple Python screen recorder
2. #Import necessary modules
3. from PIL import ImageGrab
4. import cv2
5. import numpy as np
6. from tkinter import *
Code Explanation:
from tkinter import *: We use Tkinter to build the user interface of the
application. Hence we import it to make use of the widgets and define our
application.
from PIL import ImageGrab: Take screenshot of the screen using
ImageGrab
import cv2: To write the captured screen to a video, we use opencv
import numpy as np: Convert images to arrays and vice versa
Code explanation:
Code explanation:
Code explanation:
label1: To display the background image, use an empty label with no text
attributes. The parameters are window of the application, image = loaded
background image, bd=0:setting the border to 0 or no border.
label1.pack(): Place the label in the first row, immediately after the top margin
title_label, info_label: Create a non editable text using Label. Here the
additional parameters given are: text – text to display and font styling with bg.
Font is a tuple containing the font name and the size. Specify the background
colour either using the named colours available or use pick colour or eyedropper
on firefox to get the value.
title_label.place(), info_lable.place(): To view the widgets, we position
them. Similar to pack(), place() also positions the widget. Here we mention relx
and rely which are the percentages of distance from the left and top respectively.
Anchor=CENTER positions the element in the center.
screen_button: To call the declared function, we use a button. Button() creates
a button with the parameters, window of the application, text: name of the
button, command: the function to call, relief: styling of the button. RAISED
creates a shadow effect for the button.
screen_recorder.mainloop(): When the app is run, widgets and functions
above mainloop() will be visible. The rest are simply ignored. Thus when a user
selects exit, the control flows out of mainloop and the app terminates.
Summary
Thus we created a simple Screen recorder from scratch. The project introduces
opencv and a simple application of it. We also learnt the usage of pillow to capture
screenshots and the difference in colour formats between RGB and BGR.
Tags: python project python screen recorder Screen Recorder Project using Python
1 RESPONSE
Comments 1 Pingbacks 0
LEAVE A REPLY
Comment *
Name * Email *
Save my name, email, and website in this browser for the next time I comment.
Post Comment
Trending Tutorials
Python Tutorial | Machine Learning Tutorial | AI Tutorial | OpenCV Tutorial | Django Tutorial
Python Geeks © 2024. All Rights Reserved.