Logaritmo

from tkinter import *
import math

# Configuração da janela principal
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Logaritmo")

# Título do aplicativo
titulo = Label(text="Logaritmo",
font=("Arial", 35, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.2, rely=0.05)

# Labels e Entradas para x e base
texto_sub1 = Label(text="x:",
font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.36, rely=0.3)

texto_sub2 = Label(text="Base:",
font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.25, rely=0.45)

x = StringVar()
x_entrada = Entry(textvariable=x,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
x_entrada.place(relx=0.5, rely=0.32, relwidth=0.35)
x_entrada.focus()

base = StringVar()
base_entrada = Entry(textvariable=base,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
base_entrada.place(relx=0.5, rely=0.45, relwidth=0.35)


# Função para limpar as entradas e resultado
def limpar():
base_entrada.delete(0, END)
x_entrada.delete(0, END)
resultado_texto.config(text="")


# Função para calcular e mostrar os logaritmos
def app():
try:
variavel_x = int(x.get())
variavel_base = int(base.get())
log_natural = math.log(variavel_x)
log_base_10 = math.log10(variavel_x)
log_base_2 = math.log2(variavel_x)
log_custom_base = math.log(variavel_x, variavel_base)
exp_value = math.exp(2) # e^2

mensagem = (f"Logaritmo natural de {variavel_x}: {round(log_natural,5)}\n"
f"Logaritmo base 10 de {variavel_x}: {round(log_base_10,5)}\n"
f"Logaritmo base 2 de {variavel_x}: {round(log_base_2,5)}\n"
f"Logaritmo de {variavel_x} na base {variavel_base}: {round(log_custom_base,5)}\n"
f"e^2: {round(exp_value,5)}")
resultado_texto.config(text=mensagem)

except ValueError:
resultado_texto.config(text="Erro de digitação")
except ZeroDivisionError:
resultado_texto.config(text="Base não pode ser zero")
except Exception as e:
resultado_texto.config(text=f"Erro: {str(e)}")


# Botões de ação
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.54, relwidth=0.25, relheight=0.1)

but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.54, relwidth=0.25, relheight=0.1)

but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.54, relwidth=0.25, relheight=0.1)

# Label para mostrar o resultado dos cálculos
resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.68, relwidth=0.9, relheight=0.3)

# Inicia o loop principal do tkinter
root.mainloop()

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação