Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a0c562b

Browse files
Merge pull request avinashkranjan#595 from MayankkumarTank/issue-554
Added Currency convertor - GUI based
2 parents bf7bf2b + d1b7616 commit a0c562b

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import requests
2+
import tkinter as tk
3+
from tkinter import ttk
4+
5+
def calculate_conversion():
6+
#URL of respective API
7+
url = "https://api.exchangerate-api.com/v4/latest/INR"
8+
9+
#Receive Data from API
10+
data = requests.get(url).json()
11+
currency_rates = data['rates']
12+
13+
#get From amount from GUI
14+
amount = float(from_amount.get())
15+
16+
#Get country code from GUI
17+
fc = from_currency_code.get()
18+
tc = to_currency_code.get()
19+
20+
#Logic to convert amount to INR (if county code is not INR)
21+
if fc != 'INR':
22+
amount = amount/currency_rates[fc]
23+
24+
#INR to To_country code
25+
amount = amount * currency_rates[tc]
26+
amount = round(amount,2)
27+
28+
#Set amount to Label in GUI
29+
to_amount.config(text = str(amount))
30+
31+
32+
if __name__ == '__main__':
33+
34+
#url and data extraction
35+
url = "https://api.exchangerate-api.com/v4/latest/INR"
36+
data = requests.get(url).json()
37+
currency_rates = data['rates']
38+
39+
#Building of GUI
40+
screen = tk.Tk()
41+
screen.title("Currency convertor")
42+
screen.geometry("500x300")
43+
screen.config(bg = "#282828")
44+
45+
#Introduction Label
46+
main_label = tk.Label(screen,text=" Welcome to Currency Convertor ")
47+
main_label.config(font = ("Lato",15,"bold"), anchor = "center" , bg = '#3500D3' , fg = 'white')
48+
main_label.place(x = 70,y = 10)
49+
50+
#from_amount input field and placing
51+
from_amount = tk.Entry(screen , justify = tk.CENTER)
52+
from_amount.place(x=58,y = 180)
53+
54+
#Converted amount label and it's placing
55+
to_amount = tk.Label(screen, anchor = "center" , bg = 'white' , fg = 'black', width = 16, font = ("Lato",12))
56+
to_amount.place(x=300,y = 180)
57+
58+
#Variable declation for dropdown menu and set default values
59+
from_currency_code = tk.StringVar(screen)
60+
from_currency_code.set("INR")
61+
62+
to_currency_code = tk.StringVar(screen)
63+
to_currency_code.set("INR")
64+
65+
#dropdown menu for from_currency and it's placing
66+
from_currency_menu = ttk.Combobox(screen,textvariable = from_currency_code,values = list(currency_rates.keys()),font = ("Lato",12),state = 'readonly', width = 14, justify = tk.CENTER)
67+
from_currency_menu.place(x = 61,y = 110)
68+
69+
#dropdown menu for to_currency and it's placing
70+
to_currency_menu = ttk.Combobox(screen,textvariable = to_currency_code,values = list(currency_rates.keys()),font = ("Lato",12),state = 'readonly', width = 14, justify = tk.CENTER)
71+
to_currency_menu.place(x = 303,y = 110)
72+
73+
#Convert button and placing
74+
convert_btn = tk.Button(screen, text = "Convert" , fg = 'white' , bg = "#3500D3", command = calculate_conversion)
75+
convert_btn.place(x = 230,y = 240)
76+
77+
screen.mainloop()
78+
79+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Currency Convertor - GUI based
2+
3+
## Description
4+
5+
GUI-based Currency Convertor using Tkinter in python. select the From_currency_code and To_currency_code from the GUI dropdown menu and provide the amount to be converted and after clicking the convert button you get the converted amount in provided currency. The conversion rate is founded from API. (URL of API is mentioned in code)
6+
7+
## Dependencies
8+
9+
In my work i used requests and tkinter. In most of the python installation tkinter is already installed. So, That you don't have to install. Installation for requests given below.
10+
11+
## Installation
12+
13+
```bash
14+
pip install requests
15+
```
16+
17+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /