import tkinter as tk
import requests
from functools import partial
# moeda padrão
base_currency = "BRL"
def store_currency(sel):
global base_currency
if sel == "Real Brasileiro":
base_currency = "BRL"
elif sel == "Peso Argentino":
base_currency = "ARS"
elif sel == "Guarani Paraguaio":
base_currency = "PYG"
elif sel == "Peso Uruguai":
base_currency = "UYU"
def convert(label1, label2, label3, inputn):
try:
amount = float(inputn.get())
# 🔑 coloque sua chave da API aqui
api_key = "Coloque a sua passe aqui"
url = f"https://v6.exchangerate-api.com/v6/{api_key}/latest/{base_currency}"
response = requests.get(url)
data = response.json()
rates = data["conversion_rates"]
# conversões
brl = amount * rates["BRL"]
ars = amount * rates["ARS"]
pyg = amount * rates["PYG"]
uyu = amount * rates["UYU"]
label1.config(text=f"BRL: {brl:.2f}")
label2.config(text=f"ARS: {ars:.2f}")
label3.config(text=f"PYG: {pyg:.2f} | UYU: {uyu:.2f}")
except:
label1.config(text="Erro na conversão")
# interface
root = tk.Tk()
root.geometry('400x200')
root.title('Conversor de Moedas')
numberInput = tk.StringVar()
var = tk.StringVar()
tk.Label(root, text="Valor:").grid(row=0)
tk.Entry(root, textvariable=numberInput).grid(row=0, column=1)
result1 = tk.Label(root)
result1.grid(row=2, columnspan=2)
result2 = tk.Label(root)
result2.grid(row=3, columnspan=2)
result3 = tk.Label(root)
result3.grid(row=4, columnspan=2)
options = ["Real Brasileiro", "Peso Argentino", "Guarani Paraguaio", "Peso Uruguai"]
dropdown = tk.OptionMenu(root, var, *options, command=store_currency)
var.set(options[0])
dropdown.grid(row=0, column=2)
btn = tk.Button(root, text="Converter",
command=partial(convert, result1, result2, result3, numberInput))
btn.grid(row=1, columnspan=3)
root.mainloop()