Open In App
Related Articles

Ratio Calculator GUI using Tkinter

Improve Article
Save Article
Like Article

Prerequisite: Python GUI – tkinter

Tkinter is the most commonly used library for developing GUI (Graphical User Interface) in Python. It is a standard Python interface to the Tk GUI toolkit shipped with Python. As Tk and Tkinter are available on most of the Unix platforms as well as on the Windows system, developing GUI applications with Tkinter becomes the fastest and easiest.

In this article, we are going to discuss how to create a ratio calculator using Tkinter module.

What is the Ratio Calculator? 

It is the calculator that computes the denominator base on the given ratio values. 


a = 10
b = 20
c = 30
d = ?
a : d = c : d
value of d is 60.0

Below is how the calculator will look like:

Formula Used:

a/b = c/d

Here a and b are given ratio and c is entered value for which we have to find the ratio i.e. the denominator d.

Step-by-step Approach:

  • Create Normal Tkinter Window


# Import module
from tkinter import *
# Create object
root = Tk()
# Adjust size
# Execute tkinter


  • Create One Frame using Frame() method and add three spin box using Spinbox() method.


# Create Frame
frame = Frame(Object Name)

# Create Spin Box
# Enter Range
Spinbox(frame, from_= 0, to = 10,**attr)
  • Create Another Frame, add Button, Label and create a function called as ratio_calculator, which will calculate the value of X.


# Create Frame
frame1 = Frame(Object Name)

# Create Label
Label(frame1, text="Enter Text",**attr)

# Create Button
Button(root,text="Enter Text",**attr)


Below is the implementation:


# Import Module
from tkinter import *
# Create Object
root = Tk()
# Set height and width
width = 600
height = 250
# Set Geometry and min, max size
root.maxsize(width, height)
root.minsize(width, height)
# Create Label
Label(root, text="Ratio Calculator", font=(
    "Helvetica", 18, "bold"), fg="blue").pack()
# Function will calculate the value of x
def ratio_calculator():
        # Get the value of spinbox using get() method
    s11 = int(s1.get())
    s22 = int(s2.get())
    s33 = int(s3.get())
    # Formula Used
    value = (s33*s22)/s11
    # change the text of label using config method
# Create Frame
frame = Frame(root)
# Create Spin Boxes
s1 = Spinbox(frame, from_=0, to=10000000, width=10,
             font=("Helvetica", 14, "bold"))
s1.pack(side=LEFT, padx=10, pady=10)
s2 = Spinbox(frame, from_=0, to=10000000, width=10,
             font=("Helvetica", 14, "bold"))
s2.pack(side=LEFT, padx=10, pady=10)
s3 = Spinbox(frame, from_=0, to=10000000, width=10,
             font=("Helvetica", 14, "bold"))
s3.pack(side=LEFT, padx=10, pady=10)
# Add Another Label
Label(frame, text="X", width=10, font=("Helvetica",
                                       14, "bold"),
      borderwidth=1, relief="solid").pack(side=LEFT,
# Add Another Frame
frame1 = Frame(root)
x_value = Label(frame1, text="Value of x:",
                font=("Helvetica", 18, "bold"))
value_of_x = Label(frame1, text="",
                   font=("Helvetica", 18, "bold"))
# Create Button
Button(root, text="Calculate", borderwidth=2, width=15,
       font=("Helvetica", 14, "bold"),
       command=ratio_calculator, fg="red",
# Execute Tkinter


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 Nov, 2021
Like Article
Save Article
Similar Reads
Complete Tutorials