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 0440bf1

Browse files
Add files via upload
1 parent 08b7bdd commit 0440bf1

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
GUI application that allows you to convert currency amounts between different currencies using real-time exchange rates.
2+
Convert currency amounts based on real-time exchange rates from an API.
3+
Displays conversion results in a message box.
4+
5+
Reqiurements:
6+
pip install requests
7+
8+
Note:
9+
Replace "YOUR_API_KEY" in the script with your actual API key. You can obtain an API key from the exchange rates API provider.

‎Live Currency Converter GUI/app.py‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import tkinter as tk
2+
from tkinter import messagebox
3+
import requests
4+
5+
BASE_URL = "http://api.exchangeratesapi.io/v1/latest"
6+
API_KEY = "111010136e803fdc2d600a9b204fa385"
7+
8+
class CurrencyConverterApp:
9+
def __init__(self, root):
10+
self.root = root
11+
self.root.title("Currency Converter")
12+
self.root.configure(bg="black")
13+
14+
15+
self.amount_label = tk.Label(root, text="Amount:", fg="white", bg="black")
16+
self.amount_label.pack()
17+
18+
19+
20+
self.amount_entry = tk.Entry(root)
21+
self.amount_entry.pack()
22+
23+
24+
25+
self.from_label = tk.Label(root, text="From Currency:", fg="white", bg="black")
26+
self.from_label.pack()
27+
28+
self.from_currency_entry = tk.Entry(root)
29+
self.from_currency_entry.pack()
30+
31+
32+
33+
34+
self.to_label = tk.Label(root, text="To Currency:", fg="white", bg="black")
35+
self.to_label.pack()
36+
37+
self.to_currency_entry = tk.Entry(root)
38+
self.to_currency_entry.pack()
39+
40+
41+
42+
self.convert_button = tk.Button(root, text="Convert", command=self.convert_currency)
43+
self.convert_button.pack()
44+
45+
46+
47+
def get_rates(self):
48+
payload = {"access_key": API_KEY}
49+
50+
response = requests.get(url=BASE_URL, params=payload)
51+
data = response.json()
52+
53+
return data.get("rates")
54+
55+
def get_currency(self, currency, rates):
56+
currency = currency.upper()
57+
if currency in rates.keys():
58+
59+
return rates.get(currency)
60+
61+
else:
62+
raise ValueError(f"{currency} is not a valid currency")
63+
64+
65+
66+
def convert_currency(self):
67+
amount = float(self.amount_entry.get())
68+
69+
from_currency = self.from_currency_entry.get()
70+
71+
to_currency = self.to_currency_entry.get()
72+
73+
rates = self.get_rates()
74+
75+
from_rate = self.get_currency(from_currency, rates)
76+
to_rate = self.get_currency(to_currency, rates)
77+
78+
79+
conversion = round((to_rate / from_rate) * amount, 2)
80+
81+
messagebox.showinfo("Conversion Result", f"{amount:.2f} ({from_currency}) is {conversion:.2f} ({to_currency})")
82+
83+
def main():
84+
app = tk.Tk()
85+
86+
app.configure(bg="black")
87+
88+
currency_converter = CurrencyConverterApp(app)
89+
90+
91+
app.mainloop()
92+
93+
if __name__ == "__main__":
94+
main()

0 commit comments

Comments
(0)

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