from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Diferença Quadrados")
def centralizar_janela(root):
root.update_idletasks()
largura = root.winfo_width()
altura = root.winfo_height()
x = (root.winfo_screenwidth() // 2) - (largura // 2)
y = (root.winfo_screenheight() // 2) - (altura // 2)
root.geometry(f"{largura}x{altura}+{x}+{y}")
centralizar_janela(root)
titulo = Label(text="Diferença Quadrados",
font=("Arial", "27", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="A: ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.3, rely=0.25)
texto_sub2 = Label(text="B: ",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.3, rely=0.45)
a = StringVar()
a_entrada = Entry(textvariable=a,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
a_entrada.place(relx=0.5, rely=0.25, relwidth=0.35)
a_entrada.focus()
b = StringVar()
b_entrada = Entry(textvariable=b,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
b_entrada.place(relx=0.5, rely=0.45, relwidth=0.35)
def limpar():
b_entrada.delete(0, END)
a_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
A = float(a.get())
B = float(b.get())
resultado = (A + B) * (A - B)
mensagem = f"Diferença de quadrados entre {A} e {B}\nvia fatoração é: {resultado}"
resultado_texto.config(text=mensagem, bg="#cfe2f3", fg="black")
except ValueError:
resultado_texto.config(text="Por favor, digite número válido!!", bg="red", fg="white")
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, 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.65, 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.65, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
# Vincular tecla Enter
root.bind('<Return>', lambda event: app())
root.mainloop()