Creating Currency Converter with the help of Tkinter(Python GUI)

Apr 24 · 5 min read

Let's create a Currency Converter with the help of Tkinter (A Python GUI module)

Why do we need a Currency Converter?

We need a currency converter because there are hundreds of currencies in the world and each has its own unique value compared to the other. Therefore we need a currency converter to convert the value of our currency to another currency.

Here we are going to work on a GUI-based Currency Converter that accepts the Indian rupee as input value and converts that value to US Dollar, Australian Dollar, Brazilian Real, British Pound, Chinese Yuan, etc. when the user clicks the covert button. We will use the current exchange rate for the project. (The exchange rate is the price of one currency in term of another currency).

For example, The value of 1 US dollar is equal to 72.60 ₹ Indian rupees.

Code for the project:

For the code of this project click on the link below:

Define code working:-

Tkinter is the name of the GUI library in Python. Creating a GUI application using Tkinter is an easy task.

Here in this line of the code, we import the ttk module from the Python GUI library. The ttk module provides access to the Tk-themed widget set.

converter = Tk()

converter.title(“Currency Converter”)

converter.geometry(“600x400”)

Tk class is used to create a root window. Here converter is the name of a root window. In these steps, we are giving the title of the GUI root window.Tkinter provides many methods, one of them is the geometry() method.

OPTIONS = {

“Australian Dollar”:49.10,

“Brazilian Real”:17.30,

“British Pound”:90.92,

“Chinese Yuan”:10.29,

“Euro”:77.85,

“HongKong Dollar”:8.83,

“Indonesian Rupiah”:0.004864,

“Japanese Yen”:0.628,

“Pakistani Rupee”:0.49,

“SriLankan Rupee”:0.39,

“Swiss Franc”:69.62,

“Us Dollar”:69.32

}

In the dictionary, we store the data like the country name and its currency value. Here the name of the dictionary is OPTIONS.

def ok():

price = rupees.get()

converted = float(DICT)*float(price)

result.delete(1.0,END)

Here in this line of the code, we define the Function where the function name is ok. Again, we define the price variable to hold the value of the rupees object. Get function provides getting the data from any object or any variable. Now again we define the answer variable to hold the value of the variable1 object.

Here in this line of the code define the DICT variable to hold OPTIONS value, here the option value gets the value from the answer variable. We create the Converted variable. The converted variable holds the value of the DICT*price value, we are performing multiplication on the DICT or price variable. Delete Methods provides for delete Tkinter Text Box’s Contents. Insert method allows inserting the text in the text box.

appName = Label(converter,text=”Currency Converter”,font=(“arial”,25,”bold”,”underline”),fg=”dark red”)

appName.place(x=150, y=10)

result = Text(converter,height=5,width=50,font=(“arial”,10,”bold”),bd=5)

result.place(x=125, y=60)

Now come to the Designing part of the GUI project. Here we are using some Labels, Entry Box and Buttons in a project. So let us start to comprehend the project code line by line.

Here we define the appName object of the Label Method on the GUI window and write text on the appName object and set the font and set fg, bg, or width of the object. Place method, assign the place of the appName object. In this, we define the result object of the text method and set height and width of the Text Box and set font and bd. Assigning the place of the result object using x or y coordinates values.

india = Label(converter,text=”Value in indian Rupees:”,font=(“arial”,10,”bold”),fg=”red”)

india.place(x=30, y=165)

rupees = Entry(converter,font=(“arial”,20))

rupees.place(x=200, y=160)

choice =Label(converter,text=”Choice:”,font=(“arial”,10,”bold”),fg=”red”)

choice.place(x=30, y=220)

Now again we define the India object of the Label Method on the GUI window and write text on the Label and set font and set fg of the Label. Assign the place of the India object using x or y coordinates values. We define the rupees object of the Entry Method and set the font of the Entry Method. Assigning the place of the rupees object using x or y coordinates values.

In this line of the code, we define the choice object of the Label Method and write text on the Label and set font and set fg of the Label. Again assigning the place of the choice object using x or y coordinates value.

variable1 = StringVar(converter)

variable1.set(None)

option.place(x=100 , y=210,width=100, height=40)

Now come to the next line of the code we define the variable1. Here in this line of the code Set the variable1 value to None. Here we define OptionMenu Method to hold the value of the variable1 object and OPTIONS object. Assigning the place of the OptionMenu method using x or y coordinate values and set width or height.

button=Button(converter,text=”Convert”,fg=”green”,font=(“arial”,20),bg=”powder blue”,command=ok)

button.place(x=200, y=210,height=40,width=150)

converter.mainloop()

Now come to the Button part of a project in this we are performing an action on the Button. So let’s start with how Button works?

Button Method on the GUI window and give the ok command on the Button for performing an action when Button clicks. Assign the place of the button object using x or y coordinates values and set height and width.

Coming to the last line of code of the project is the mainloop function that provides an infinite loop. So let’s start to comprehend how it works. mainloop() is an infinite loop used to run the application, using this function window is not closed as long as.

Here we complete a full GUI Project using the Python Tkinter module and ttk module.

Refer to our more Blogs on Python from the link below:

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Written by

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Forward Cybernetica

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app