55BASE_URL = "http://api.exchangeratesapi.io/v1/latest"
66API_KEY = "Your API Key"
77
8+
89class CurrencyConverterApp :
910 def __init__ (self , root ):
1011 self .root = root
1112 self .root .title ("Currency Converter" )
1213 self .root .configure (bg = "black" )
1314
14-
15- self . amount_label = tk . Label ( root , text = "Amount:" , fg = "white" , bg = "black" )
15+ self . amount_label = tk . Label (
16+ root , text = "Amount:" , fg = "white" , bg = "black" )
1617 self .amount_label .pack ()
1718
18-
19-
2019 self .amount_entry = tk .Entry (root )
2120 self .amount_entry .pack ()
2221
23-
24-
25- self .from_label = tk .Label (root , text = "From Currency:" , fg = "white" , bg = "black" )
22+ self .from_label = tk .Label (
23+ root , text = "From Currency:" , fg = "white" , bg = "black" )
2624 self .from_label .pack ()
2725
2826 self .from_currency_entry = tk .Entry (root )
2927 self .from_currency_entry .pack ()
3028
31-
32-
33-
34- self .to_label = tk .Label (root , text = "To Currency:" , fg = "white" , bg = "black" )
29+ self .to_label = tk .Label (
30+ root , text = "To Currency:" , fg = "white" , bg = "black" )
3531 self .to_label .pack ()
3632
3733 self .to_currency_entry = tk .Entry (root )
3834 self .to_currency_entry .pack ()
3935
40-
41-
42- self .convert_button = tk .Button (root , text = "Convert" , command = self .convert_currency )
36+ self .convert_button = tk .Button (
37+ root , text = "Convert" , command = self .convert_currency )
4338 self .convert_button .pack ()
4439
45-
46-
4740 def get_rates (self ):
4841 payload = {"access_key" : API_KEY }
4942
@@ -61,8 +54,6 @@ def get_currency(self, currency, rates):
6154 else :
6255 raise ValueError (f"{ currency } is not a valid currency" )
6356
64-
65-
6657 def convert_currency (self ):
6758 amount = float (self .amount_entry .get ())
6859
@@ -75,10 +66,11 @@ def convert_currency(self):
7566 from_rate = self .get_currency (from_currency , rates )
7667 to_rate = self .get_currency (to_currency , rates )
7768
78-
7969 conversion = round ((to_rate / from_rate ) * amount , 2 )
8070
81- messagebox .showinfo ("Conversion Result" , f"{ amount :.2f} ({ from_currency } ) is { conversion :.2f} ({ to_currency } )" )
71+ messagebox .showinfo (
72+ "Conversion Result" , f"{ amount :.2f} ({ from_currency } ) is { conversion :.2f} ({ to_currency } )" )
73+
8274
8375def main ():
8476 app = tk .Tk ()
@@ -87,8 +79,8 @@ def main():
8779
8880 currency_converter = CurrencyConverterApp (app )
8981
90-
9182 app .mainloop ()
9283
84+
9385if __name__ == "__main__" :
9486 main ()
0 commit comments