Mundo em Python

Tensão na resistência (usando Tkinter)

from tkinter import *
root = Tk()
root.title("Tensão na resistência")
root.configure(bg="#cfe2f3")
root.geometry("600x150")
root.resizable(0,0)
def app(*args):
vr = vresistencia.get()
vc = vcorrente.get()
tensao = vr *vc
tarr = round(tensao,4)
mensagem = f'A tensão vale: {tarr} volt'
resultado.set(mensagem) def limpar():
vcorrente_entrada.delete(0, END)
vresistencia_entrada.delete(0, END) texto1 = Label(text="Resistência ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
texto1.place(relx=0.05,rely=0.1)
texto2= Label(text="ohm ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
texto2.place(relx=0.4,rely=0.1) texto3= Label(text="Corrente",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
texto3.place(relx=0.5,rely=0.1) texto4= Label(text="ampere",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
texto4.place(relx=0.8,rely=0.1) vresistencia = DoubleVar()
vresistencia_entrada= Entry(textvariable=vresistencia,
font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
vresistencia_entrada.place(relx=0.23,rely=0.1,relwidth=0.15)
vcorrente = DoubleVar()
vcorrente_entrada= Entry(textvariable=vcorrente,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
vcorrente_entrada.place(relx=0.65,rely=0.1,relwidth=0.15)
but1 = Button( text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'),command=app)
but1.place(relx=0.6, rely=0.45, relwidth=0.25, relheight=0.2)
but_limpar = Button( text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'),command=limpar)
but_limpar.place(relx=0.6, rely=0.7, relwidth=0.25, relheight=0.2)
resultado = StringVar()
resulatdoresultado =Label(textvariable=resultado,
font=("Arial",12,"bold"),bg="#f0f8ff")
resulatdoresultado.place(relx=0.05,rely=0.7,relwidth=0.5)
vcorrente_entrada.focus()
root.bind("<Return>", app)
root.mainloop()
0