UNIDAD 5: PROYECTO FINAL

 #  U5 PROYECTO FINAL.py

#  HACER UNA CALCULADORA DE RESISTENCIAS

#  11/06/2021

#Hecho por PAVEL OMAR DÍAS HERNANDEZ 

#Hecho por LUIS IGNACIO MEDINA GÓMEZ

from tkinter import *

import tkinter

import tkinter.font as tkFont

import io

from tkinter import messagebox

from datetime import date

from datetime import datetime


letra='Black'

bandas=['CUATRO (4)','CINCO (5)']

colores=['Black','SaddleBrown','Red','Orange','Yellow','Green','Blue','Purple','Gray','White']

numeros={'Black':0,'SaddleBrown':1,'Red':2,'Orange':3,'Yellow':4,'Green':5,'Blue':6,'Purple':7,'Gray':8,'White':9}

multi=['Black','SaddleBrown','Red','Orange','Yellow','Green','Blue','Purple','Goldenrod','Silver']

porcuanto={'Black':1,'SaddleBrown':10,'Red':100,'Orange':1000,'Yellow':10000,'Green':100000,'Blue':1000000,'Purple':10000000,'Goldenrod':.1,'Silver':.01}

toler=['Goldenrod','Silver','SaddleBrown','Red','Green','Blue','Purple','Gray']

acepta={'Goldenrod':'  5%','Silver':'  10%','SaddleBrown':'  1%','Red':'  2%','Green':'  0.5%','Blue':'  0.25%','Purple':'  0.1%','Gray':'  0.05%'}

lista=[]


def cambiar(x):

if opcion.get()=='CUATRO (4)':

c.delete('all')

c.create_line(275,10,275,690,width=50,fill="DimGray")

c.create_polygon(80,100,130,50,420,50,470,100,470,200,420,250,420,450,470,500,470,600,420,650,130,650,80,600,80,500,130,450,130,250,80,200,fill="BurlyWood")

c.create_line(80,150,470,150,width=40,fill=color1.get())

c.create_line(130,270,420,270,width=40,fill=color2.get())

c.create_line(130,340,420,340,width=40,fill=multiplicador.get())

c.create_line(80,550,470,550,width=40,fill=tolerancia.get())

c.create_line(80,100,130,50,420,50,470,100,470,200,420,250,420,450,470,500,470,600,420,650,130,650,80,600,80,500,130,450,130,250,80,200,80,100,width=5,fill="black")

menu3.place(x=280,y=720)

if color1.get()=='Black':

letra='White'

else:

letra='Black' 

menu1.configure(borderwidth="0",highlightthickness="0",bg=color1.get(),fg=letra,font='12')

menu1.place(x=285,y=140)

LB11.configure(bg=color1.get(),fg=letra,font='12')

LB11.place(x=145,y=140)

if color2.get()=='Black':

letra='White'

else:

letra='Black' 

menu2.configure(borderwidth="0",highlightthickness="0",bg=color2.get(),fg=letra,font='12')

menu2.place(x=285,y=260)

LB12.configure(bg=color2.get(),fg=letra,font='12')

LB12.place(x=145,y=260)

if multiplicador.get()=='Black':

letra='White'

else:

letra='Black' 

menu4.configure(borderwidth="0",highlightthickness="0",bg=multiplicador.get(),fg=letra,font='12')

menu4.place(x=285, y=330)

LB14.configure(bg=multiplicador.get(),fg=letra,font='12')

LB14.place(x=145,y=330)

if tolerancia.get()=='Black':

letra='White'

else:

letra='Black' 

menu5.configure(borderwidth="0",highlightthickness="0",bg=tolerancia.get(),fg=letra,font='12')

menu5.place(x=285, y=540)

LB15.configure(bg=tolerancia.get(),fg=letra,font='12')

LB15.place(x=145,y=540)

elif opcion.get()=='CINCO (5)':

c.delete('all')

c.create_line(275,10,275,690,width=50,fill="DimGray")

c.create_polygon(80,100,130,50,420,50,470,100,470,200,420,250,420,450,470,500,470,600,420,650,130,650,80,600,80,500,130,450,130,250,80,200,fill="BurlyWood")

c.create_line(80,150,470,150,width=40,fill=color1.get())

c.create_line(130,270,420,270,width=40,fill=color2.get())

c.create_line(130,340,420,340,width=40,fill=color3.get())

c.create_line(130,410,420,410,width=40,fill=multiplicador.get())

c.create_line(80,550,470,550,width=40,fill=tolerancia.get())

c.create_line(80,100,130,50,420,50,470,100,470,200,420,250,420,450,470,500,470,600,420,650,130,650,80,600,80,500,130,450,130,250,80,200,80,100,width=5,fill="black")

if color1.get()=='Black':

letra='White'

else:

letra='Black' 

menu1.configure(borderwidth="0",highlightthickness="0",bg=color1.get(),fg=letra,font='12')

menu1.place(x=285,y=140)

LB11.configure(bg=color1.get(),fg=letra,font='12')

LB11.place(x=145,y=140)

if color2.get()=='Black':

letra='White'

else:

letra='Black' 

menu2.configure(borderwidth="0",highlightthickness="0",bg=color2.get(),fg=letra,font='12')

menu2.place(x=285,y=260)

LB12.configure(bg=color2.get(),fg=letra,font='12')

LB12.place(x=145,y=260)

if color3.get()=='Black':

letra='White'

else:

letra='Black' 

menu3.configure(borderwidth="0",highlightthickness="0",bg=color3.get(),fg=letra,font='12')

menu3.place(x=285,y=330)

LB13.configure(bg=color3.get(),fg=letra,font='12')

LB13.place(x=145,y=330)

if multiplicador.get()=='Black':

letra='White'

else:

letra='Black' 

menu4.configure(borderwidth="0",highlightthickness="0",bg=multiplicador.get(),fg=letra,font='12')

menu4.place(x=285, y=400)

LB14.configure(bg=multiplicador.get(),fg=letra,font='12')

LB14.place(x=145,y=400)

if tolerancia.get()=='Black':

letra='White'

else:

letra='Black' 

menu5.configure(borderwidth="0",highlightthickness="0",bg=tolerancia.get(),fg=letra,font='12')

menu5.place(x=285, y=540)

LB15.configure(bg=tolerancia.get(),fg=letra,font='12')

LB15.place(x=145,y=540)

else:

print("Raro")


def calcular():

if opcion.get()=='CUATRO (4)':

banda1=int(numeros[color1.get()])

banda2=int(numeros[color2.get()])

banda3=float(porcuanto[multiplicador.get()])

banda4=str(acepta[tolerancia.get()])

valor=((banda1*10)+banda2)*banda3

final=str(valor)+' Ω '+banda4

final1=str(valor)+' Ohms '+banda4

Resultado.configure(text=final,bg='LightBlue',fg='Black')

Resultado.place(x=550,y=550)

guardar(final1)

else:

banda1=int(numeros[color1.get()])

banda2=int(numeros[color2.get()])

banda3=int(numeros[color3.get()])

banda4=float(porcuanto[multiplicador.get()])

banda5=str(acepta[tolerancia.get()])

valor=((banda1*100)+(banda2*10)+banda3)*banda4

final=str(valor)+' Ω '+banda5

final1=str(valor)+' Ohms'+banda5

Resultado.configure(text=final,bg='LightBlue',fg='Black')

Resultado.place(x=550,y=550)

guardar(final1)


def iniciarArchivo():

archivo=open("resistencia.txt","a")

archivo.close()


def guardar(final1):

archivo=open("resistencia.txt","a")

now = datetime.now() 

if opcion.get()=='CUATRO (4)':

guarda=("El día {} del mes {} del año {}, a las {}:{} se hizo el calculo:".format(now.day,now.month,now.year,now.hour,now.minute))

guarda1=("{}, {}, {}, {} = {}".format(color1.get(),color2.get(),multiplicador.get(),tolerancia.get(),final1))

else:

guarda=("El día {} del mes {} del año {}, a las {}:{} se hizo el calculo:".format(now.day,now.month,now.year,now.hour,now.minute))

guarda1=("{}, {}, {}, {}, {} = {}".format(color1.get(),color2.get(),color3.get(),multiplicador.get(),tolerancia.get(),final1))

archivo.write(guarda+'\n'+guarda1+'\n\n')

archivo.close

r=historial()

r.insert(INSERT,guarda+'\n'+guarda1+'\n\n')


def historial():

archivo=open("resistencia.txt","r")

r=Text(ventana,width=68, height=30)

linea=archivo.readlines()

for x in range(len(linea)):

r.insert(INSERT, linea[x])

r.place(x=750,y=150)

archivo.close

return(r)


def borrar():

try:

for i in lista:

lista.remove(i)

except: 

print('Raro')

archivo=open("resistencia.txt","w")

archivo.close()

messagebox.showinfo("Historial Eliminado","El historial ha sido eliminado correctamente")

r=Text(ventana,width=68, height=30)

r.place(x=750,y=150)



ventana=Tk()

ventana.geometry("1300x700")

ventana.title("Proyecto Final")

c=Canvas(ventana, width=700, height=700)

c.place(x=0,y=0)

final=' '

opcion=StringVar(value='CUATRO (4)')

color1=StringVar(value='Black')

color2=StringVar(value='Black')

color3=StringVar(value='Black')

multiplicador=StringVar(value='Black')

tolerancia=StringVar(value='Goldenrod')

font1=tkFont.Font(size=30)

font2=tkFont.Font(size=15)

etiqueta1=Label(ventana,text="CALCULADORA DE RESITENCIAS: ",font=font1).place(x=520,y=25)

etiqueta2=Label(ventana,text="NÚMERO DE BANDAS: ",font='12').place(x=500,y=120)

etiqueta3=Label(ventana,text="HISTORIAL: ",font='12').place(x=1010,y=120)

menu0=OptionMenu(ventana, opcion, *bandas,command=cambiar)

menu0.configure(font='12')

menu0.place(x=500, y=150)

etiqueta2=Label(ventana,text="VALOR DE LA RESISTENCIA: ",font='12').place(x=500,y=520)

Resultado=Label(ventana,text='-----------',bg='LightBlue',fg='Black',font=font2)

menu1=OptionMenu(ventana, color1, *colores,command=cambiar)

LB11=Label(ventana,text="COLOR 1:",bg=color1.get(),fg=letra)

menu2=OptionMenu(ventana, color2, *colores,command=cambiar)

LB12=Label(ventana,text="COLOR 2:",bg=color2.get(),fg=letra)

menu3=OptionMenu(ventana, color3, *colores,command=cambiar)

LB13=Label(ventana,text="COLOR 3:",bg=color3.get(),fg=letra)

menu4=OptionMenu(ventana, multiplicador, *multi,command=cambiar)

LB14=Label(ventana,text="MULTIPLICADOR:",bg=multiplicador.get(),fg=letra)

menu5=OptionMenu(ventana, tolerancia, *toler,command=cambiar)

LB15=Label(ventana,text="TOLERANCIA:",bg=tolerancia.get(),fg=letra)

btn1=Button(ventana,text="SALIR",bg='Red',command=ventana.quit,font='12').place(x=1238,y=650)

btn2=Button(ventana,text="CALCULAR RESISTENCIA",bg='LightBlue',command=calcular,font='12').place(x=750,y=650)

btn3=Button(ventana,text="BORRAR HISTORIAL",command=borrar,font='12').place(x=1015,y=650)


iniciarArchivo()

cambiar(0)

historial()

ventana.mainloop()


INICIO DEL PROGRAMA (SIN NADA EN LA AGENDA).

PARA RESISTENCIAS DE 4 BANDAS

PARA RESISTENCIAS DE 5 BANDAS

BOTÓN DE BORRAR HISTORIAL

AGENDA:
CREA UN ARCHIVO DE TEXTO LLAMADO "resistencia.txt"




Comentarios