Skip to main content

Image Editing Software | GUI Designing | Creating Radio Buttons

Hello Friends! Let us continue our development of Image editing software. In this tutorial, we will add radio buttons to our GUI. These radio buttons will be used to apply different types of color filters to the image. Check out the video below.



Let us start by creating a new frame for radio buttons and let us anchor it to the north side.

Frame3 = tk.Frame(window, height=20)
Frame3.pack(anchor=tk.N)

Now, let's add radio buttons to this frame. We will be creating 5 radio buttons (pink, orange, blue, yellow, none) and pack them using the grid.

yellowButton = tk.Radiobutton(Frame3, text="Yellow", width=20, value=1, command=yellowButton_callback)
yellowButton.grid(row=0, column=0)

blueButton = tk.Radiobutton(Frame3, text="Blue", width=20, value=2, command=blueButton_callback)
blueButton.grid(row=0, column=1)

orangeButton = tk.Radiobutton(Frame3, text="Orange", width=20, value=3, command=orangeButton_callback)
orangeButton.grid(row=0, column=2)

pinkButton = tk.Radiobutton(Frame3, text="Pink", width=20, value=4, command=pinkButton_callback)
pinkButton.grid(row=0, column=3)

noneButton = tk.Radiobutton(Frame3, text="None", width=20, value=5, command=noneButton_callback)
noneButton.grid(row=0, column=4)

The parameters that we have passed are explained below:-

1. Frame3 - Frame on which you want to display the button

2. text - the label that will appear next to the radio button

3. width - width of the label in characters

4. value - when a radio button is switched on, its control variable is set to its current value option. Give each radio button in a group a different integer value.

5. command - the method that will be executed when the button is pressed.

Let us now define the callback methods for all the radio buttons.

def yellowButton_callback():
pass

def blueButton_callback():
pass

def pinkButton_callback():
pass

def orangeButton_callback():
pass

def noneButton_callback():
pass

Now if you run this code the output will be as follows:-


Are you able to see the problem? By default, all the radio buttons are selected. We just want the none button to be selected by default. To do that just add the following line to your code.

noneButton.select()

Adding the above line will give you the perfect output.



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