Logaritmo (Usando Tkinter e terminal)
# Usando Tkinter
from tkinter import *
from tkinter import ttk
import math
root=Tk()
class applogaritemo():
def __init__(self):
self.root = root
self.janela()
self.frames_da_janela()
self.widgets_frame1()
self.Menus()
root.mainloop()
def janela(self):
self.root.title("Logaritmo")
self.root.configure(background='#1e3743')
self.root.geometry("300x300")
self.root.resizable(0,0)
def frames_da_janela(self):
self.frame_1 = Frame(self.root, bd=4,
bg='#dfe3ee',
highlightbackground='#759fe6',
highlightthickness=2)
self.frame_1.place(relx=0.02, rely=0.02,
relwidth=0.96, relheight=0.96)
def widgets_frame1(self):
self.abas = ttk.Notebook(self.frame_1)
self.rlog = Frame(self.abas)
self.rlogbase = Frame(self.abas)
self.rlog.configure(background="#dfe3ee")
self.rlogbase.configure(background="#dfe3ee")
self.abas.add(self.rlog, text="Logaritmo")
self.abas.add(self.rlogbase, text="Logaritmo com base")
self.abas.place(relx=0, rely=0, relwidth=0.98, relheight=0.98)
# Logaritmo
self.numeronatural = IntVar()
self.lb_numeronatural = Label(self.rlog,
text="Número Natural"
,bg='#dfe3ee', fg='#107db2')
self.lb_numeronatural.place(relx=0.2, rely=0.05)
self.numeronatural_entry = Entry(self.rlog,
textvariable=self.numeronatural,justify='center')
self.numeronatural_entry.place(relx=0.6, rely=0.05, relwidth=0.15)
self.bt_calcular1 = Button(self.rlog, text="Calcular",
bd=2,bg='#107db2', fg='white',
font=('verdana', 12, 'bold'),
command=self.butaoclick1)
self.bt_calcular1.place(relx=0.3, rely=0.3, relwidth=0.45, relheight=0.1)
self.resultadolog = StringVar()
self.resultado1 = Label(self.rlog, textvariable=self.resultadolog)
self.resultado1.place(relx=0.55, rely=0.7, relwidth=0.3)
self.lb_resultado1 = Label(self.rlog, text="Logaritmo",
bg='#dfe3ee', fg='#107db2')
self.lb_resultado1.place(relx=0.25, rely=0.7)
#Logaritmo Base
self.numeronatural1 = IntVar()
self.lb_numeronatural1 = Label(self.rlogbase,
text=" Número Natural ",
bg='#dfe3ee', fg='#107db2')
self.lb_numeronatural1.place(relx=0.15, rely=0.2)
self.numeronatural1_entry = Entry(self.rlogbase,
textvariable=self.numeronatural1,
justify='center')
self.numeronatural1_entry.place(relx=0.55, rely=0.2, relwidth=0.15)
self.base = IntVar()
self.lb_base= Label(self.rlogbase, text="Base",bg='#dfe3ee', fg='#107db2')
self.lb_base.place(relx=0.15, rely=0.4)
self.lb_base_entry = Entry(self.rlogbase,
textvariable=self.base,justify='center')
self.lb_base_entry.place(relx=0.55, rely=0.4, relwidth=0.15)
# Butão de Calcular
self.bt_calcular2 = Button(self.rlogbase,text="Calcular", bd=2,bg='#107db2',
fg='white',
font=('verdana', 12, 'bold')
,command=self.butaoclick2)
self.bt_calcular2.place(relx=0.25, rely=0.6, relwidth=0.4, relheight=0.1)
# Resultado
self.resultadologaratimobase = StringVar()
self.resultado2 = Label(self.rlogbase,
textvariable=self.resultadologaratimobase)
self.resultado2.place(relx=0.5, rely=0.8, relwidth=0.4)
self.lb_resultado2 = Label(self.rlogbase,
text="Logaritmo",bg='#dfe3ee', fg='#107db2')
self.lb_resultado2.place(relx=0.06, rely=0.8)
def butaoclick1(self):
n = self.numeronatural.get()
r = math.log(n)
rarredondar = round(r,4)
return self.resultadolog.set(rarredondar)
def butaoclick2(self):
a = self.numeronatural1.get()
b = self.base.get()
log_r = math.log(a,b)
log_r_arrundanda = round(log_r, 4)
return self.resultadologaratimobase.set(log_r_arrundanda)
def Quit(self):
self.root.destroy()
def Menus(self):
menubar = Menu(self.root)
self.root.config(menu=menubar)
filemenu = Menu(menubar)
menubar.add_cascade(label="Opções", menu=filemenu)
filemenu.add_command(label="Sair", command=self.Quit)
applogaritemo()
# Terminal
import math
numero_natural = int(input("Número Natural: "))
log1 = math.log(numero_natural)
log1arr = round(log1,4)
print(f'O logaritmo de {numero_natural} é {log1arr}.')
# Terminal com base
import math
numero_natural = int(input("Número Natural: "))
base = int(input("Digite Base: "))
log1 = math.log(numero_natural,base)
log1arr = round(log1,4)
print(f'O logaritmo de {numero_natural} é {log1arr}.')
Comentários
Enviar um comentário