Skip to main content

Image Editing Software | GUI Designing | Creating Sliders

 Hello friends! Let us continue developing our GUI of image editing software. You can check out the previous post by clicking here, where we have learned to create a window and add a few buttons to it. In this post, we will be adding sliders to our GUI which will be used to adjust the brightness and contrast of the image. You can check out the video below.



We will continue developing our previous code. For placing the sliders we will use another frame. For creating the frame use the code below. 

Frame2 = tk.Frame(window, height=20)
Frame2.pack(anchor=tk.NW)

Frame2 will be holding the sliders of brightness and contrast adjustments. We have anchored the Frame2 to the northwest corner in our window. Let us now create the sliders for our window. 

brightnessSlider = tk.Scale(Frame2, label="Brightness", from_=0, to=2, orient=tk.HORIZONTAL, 
length=screen_width, resolution=0.1, command=brightness_callback)
brightnessSlider.pack(anchor=tk.N)

contrastSlider = tk.Scale(Frame2, label="Contrast", from_=0, to=255, orient=tk.HORIZONTAL,
length=screen_width, command=contrast_callback)
contrastSlider.pack(anchor=tk.N)

The meaning of all the parameters is as follows:

1. Frame2:- The frame on which you want to place the slider(use window name if you do not want to create a frame).

2. label:- Name of the slider.

3. from_:- The lowest value of the slider.

4. to:- The highest value of the slider.

5. orient:- Orientation of the slider(horizontal/vertical).

6. length:- length of the slider.

7. resolution:- The smallest incremental value of the scale(by default this is 1).

8. command:- The method that will be executed when the slider is moved.

We have anchored the sliders to the north side of Frame2. Now let us define the methods that will be executed when the slider is moved.

def brightness_callback(brightness_pos):
print(brightness_pos)

def contrast_callback(contrast_pos):
print(contrast_pos)

As you can see above, the methods take one argument which returns the current position of the slider. We will print this to know the current slider position.

Our code is now ready to run. 



Happy coding...!!!

For full code click here.







Comments

Popular posts from this blog

Iris Detection | Python | OpenCv

 Hello there! Welcome to another blog. In this blog you are going to learn to detect iris using OpenCv python. Here is the video in case you missed it. So, let's get started. We will start by importing the necessary libraries. import cv2 import numpy as np Now, let us import the face and eye classifier files and set the camera resolution as follows. eye = cv2.CascadeClassifier( 'haarcascade_eye.xml' ) face = cv2.CascadeClassifier( 'haarcascade_frontalface_alt.xml' ) Kernal = np.ones(( 3 , 3 ) , np.uint8) #Declare kernal for morphology cap = cv2.VideoCapture( 0 ) cap.set(cv2.CAP_PROP_FRAME_WIDTH , 320 ) ##Set camera resolution cap.set(cv2.CAP_PROP_FRAME_HEIGHT , 240 ) In a while loop let us capture an image frame, flip it(in case your camera captures inverted images) and convert it into a gray scale image. ret , frame = cap.read() ##Read image frame frame = cv2.flip(frame , + 1 ) ##Flip the image in case your camera

Object Distance Calculation Using Contour Area Method In Python - Opencv

Today we will discuss how you can find the distance of an object from the camera using python OpenCV. Check out the video below. Before we continue, you should know how to detect a colored object. Click this link to check out my previous blog on object detection and tracking. I hope after checking out my previous blog, you are able to write your own code to detect and track objects. We will take forward the Object detection and tracking code to find the distance of an object from the camera. So let's start. Let us first understand the principle using which we will find the distance of the object from the camera. Principle:- Area enclosed by the contours of an object decreases as the object moves farther from the camera. This simply means that, if your object is near to the camera, the object will appear bigger. Thus the pixel area occupied by the object will be very large. As you move the object farther from the camera, the object size in the image will start to d

Object Detection And Tracking using Python - Opencv

Let us discuss today how you can detect and track an object in real-time. We will be using Python language and Opencv library for this purpose. Check out the video below. If you have read my previous blogs, you can directly skip down to the contour part. As usual, we need to make a few assumptions for the proper working of this application. This background is always static i.e. there is no addition or subtraction of objects in the background scene. The background-color is always constant. It does not change with time. The object that will be used for writing/painting is of a different color than the background to give us sufficient contrast between foreground and background. We are ready to begin now. Let us start by installing necessary python libraries for our project using  pip install.  We will be needing  Numpy  and  Opencv  libraries. Now create a python project and create a new script. Import the required libraries into python script as shown below. import cv2