Código de Python - CALCULADORA DE DIVISAS

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python

CALCULADORA DE DIVISASgráfica de visualizaciones


Python

Publicado el 3 de Mayo del 2024 por Antonio (76 códigos)
293 visualizaciones desde el 3 de Mayo del 2024
Programa para convertir cantidades de moneda a otras divisas (el programa muestra la tasa de cambio y el equivalente en la otra moneda) usando datos actualizados.

cuc
PARA CUALQUIER DUDA U OBSERVACIÓN USEN LA SECCIÓN DE COMENTARIOS.

Requerimientos

Lenguaje: Python 3.12.1
Librerias externas: forex-python 1.8

1.1

Publicado el 3 de Mayo del 2024gráfica de visualizaciones de la versión: 1.1
293 visualizaciones desde el 3 de Mayo del 2024
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import Tk, filedialog, messagebox, ttk
from forex_python.converter import CurrencyRates, CurrencyCodes
import os
import threading
 
class Currency_calc:
    def __init__(self):
        self.rates = CurrencyRates()
        self.symbols = CurrencyCodes()
        self.root = Tk()
        self.root.title("Currency Calculator")
        self.root.geometry("541x530")
        self.root.resizable(height=tk.FALSE,width=tk.FALSE)
        self.currencies = {'US Dollar':'USD','Euro':'EUR','Canadian Dollar':'CAD','Pound':'GBP',
                           'Japanese Yen':'JPY','Australian Dollar':'AUD','New Zeland Dollar':'NZD',
                           'Swiss Franc':'CHF','Hong Kong Dollar':'HKD','Swedish Crown':'SEK',
                           'Norwegian Crown':'NOK','Dannish Crown':'DKK','Chinese Yuan':'CNY',
                           'Mexican Peso':'MXN','Turkish Lira':'TRY','South African Rand':'ZAR',
                           'Polish Zloty':'PLN','Hungarian Forint':'HUF','Taiwan Dollar':'TWD',
                           'Indian Rupee':'INR','Singapore Dollar':'SGD','Philippine Peso':'PHP',
                           'Brazilian Real':'BRL','Indonesian Rupiah':'IDR','Thai Baht':'THB'}
 
        sorted_currencies = sorted(self.currencies.keys()) # EN ORDEN ALFABETICO
 
        # Mostrar directorio de ejecución
        self.current_dir = tk.StringVar()
        self.current_dir.set(os.getcwd())
        entry_dir = tk.Entry(self.root,textvariable=self.current_dir,width=90)
        entry_dir.place(x=0,y=0)
 
        # Listas desplegables
        self.currency_selector = ttk.Combobox(self.root,width=30)
        self.currency_selector["values"] = sorted_currencies
        self.currency_selector.set('US Dollar')
        self.currency_selector.place(x=20, y=80)
        tk.Label(self.root,text="TO",width=5,font=('Arial',10,"bold")).place(x=246,y=80)
        self.ex_label = tk.Label(self.root,text="",width=30,font=('Arial',10),fg="red",anchor="w")
        self.ex_label.place(x=16,y=120)
        self.currency_selector2 = ttk.Combobox(self.root,width=30)
        self.currency_selector2["values"] = sorted_currencies
        self.currency_selector2.set('Euro')
        self.currency_selector2.place(x=317, y=80)
 
        # Entrada de cantidad y etiqueta para resultado
        self.amount = tk.StringVar()
        self.amount.set("")
        self.amount_entry = tk.Entry(self.root,textvariable=self.amount,width=33,font=('Arial',20,"bold"))
        self.amount_entry.place(x=20, y=140)
        self.result_label = tk.Label(self.root,width=29,font=('Arial',20,"bold"),bg="bisque")
        self.result_label.place(x=20,y=190)
 
        # Botones
        tk.Button(self.root,text="7",width=21,height=2,command=lambda:self.btnClick('7')).place(x=20,y=245)
        tk.Button(self.root,text="8",width=21,height=2,command=lambda:self.btnClick('8')).place(x=192,y=245)
        tk.Button(self.root,text="9",width=21,height=2,command=lambda:self.btnClick('9')).place(x=362,y=245)
        tk.Button(self.root,text="4",width=21,height=2,command=lambda:self.btnClick('4')).place(x=20,y=300)
        tk.Button(self.root,text="5",width=21,height=2,command=lambda:self.btnClick('5')).place(x=192,y=300)
        tk.Button(self.root,text="6",width=21,height=2,command=lambda:self.btnClick('6')).place(x=362,y=300)
        tk.Button(self.root,text="1",width=21,height=2,command=lambda:self.btnClick('1')).place(x=20,y=355)
        tk.Button(self.root,text="2",width=21,height=2,command=lambda:self.btnClick('2')).place(x=192,y=355)
        tk.Button(self.root,text="3",width=21,height=2,command=lambda:self.btnClick('3')).place(x=362,y=355)
        tk.Button(self.root,text="RESET",width=21,height=2,command=self.reset_display).place(x=20,y=410)
        tk.Button(self.root,text="0",width=21,height=2,command=lambda:self.btnClick('0')).place(x=192,y=410)
        tk.Button(self.root,text=".",width=21,height=2,command=lambda:self.btnClick('.')).place(x=362,y=410)
 
        tk.Button(self.root,text="CALCULATE",width=70,height=2,command=self.init_task).place(x=20,y=465)
 
        self.root.mainloop()
 
    # Definir cantidad y mostrarl en el entry
    def btnClick(self,num):
        if num == "." and "." in self.amount_entry.get():
            return
        self.amount.set(self.amount_entry.get() + num)
 
    # Resetear display
    def reset_display(self):
        self.amount.set("")
 
    # Define ticker
    def create_ticker(self):
        t1 = self.currencies[self.currency_selector.get()]
        t2 = self.currencies[self.currency_selector2.get()]
        return t1, t2
 
    # Descarga tipo de cambio actualizado y realiza multiplicación
    def calculate(self):
        try:
 
            amount = float(self.amount.get())
            ticker1, ticker2 = self.create_ticker()
            ticker2_symbol = self.symbols.get_symbol(ticker2)
            currency_rate = str(self.rates.get_rate(ticker1,ticker2))
            self.ex_label.configure(text=f'RATE ({ticker1}/{ticker2}) = {currency_rate}')
            total = self.rates.convert(ticker1, ticker2, amount)
            self.result_label.configure(text=str(round(total,4))+" "+ticker2_symbol)
 
        except Exception as e:
            messagebox.showwarning("ERROR",str(e))
            self.result_label.configure(text="")
 
    # Inicia la ejecución de la función 'calculate()'
    def init_task(self):
        self.ex_label.configure(text="")
        if self.currency_selector.get() != "" and  self.currency_selector2.get() != "":
            if self.amount_entry.get() != "":
                self.result_label.configure(text="CALCULATING...")
                task = threading.Thread(target=self.calculate)
                task.start()
            else:
                messagebox.showwarning("ERROR","Enter amount for conversion")
        else:
             messagebox.showwarning("ERROR","No currencies selected")
 
if __name__ == '__main__':
    Currency_calc()



Comentarios sobre la versión: 1.1 (0)


No hay comentarios
 

Comentar la versión: 1.1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7508