Mundo em Python

Força de Gravidade (usando Tkinter)

from tkinter import *
root = Tk()
root.geometry("450x400")
root.resizable(0, 0)
root.config(bg="#125280")
root.title("Força de Gravidade") titulo = Label(text="Força de Gravidade",
font=("Arial", "32", "bold"),bg="#125280",fg="#0dbfb3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="Massa Objecto 1 (em quilogramas):",
font=("Arial", "12", "bold"),bg="#125280",fg="#0dbfb3")
texto_sub1.place(relx=0.05, rely=0.25) texto_sub2 = Label(text="Massa Objecto 2 (em quilogramas):",
font=("Arial", "12", "bold"),bg="#125280",fg="#0dbfb3")
texto_sub2.place(relx=0.05, rely=0.4) texto_sub3 = Label(text="Distância (em metros):",
font=("Arial", "12", "bold"),bg="#125280",fg="#0dbfb3")
texto_sub3.place(relx=0.25, rely=0.55)
m1 = DoubleVar()
m1_entrada = Entry(textvariable=m1,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
m1_entrada.place(relx=0.65, rely=0.25, relwidth=0.3) m2 = DoubleVar()
m2_entrada = Entry(textvariable=m2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
m2_entrada.place(relx=0.65, rely=0.4, relwidth=0.3) Distância = DoubleVar()
Distância_entrada = Entry(textvariable=Distância,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Distância_entrada.place(relx=0.65, rely=0.55, relwidth=0.3)
def limpar():
Distância_entrada.delete(0, END)
m1_entrada.delete(0, END)
m2_entrada.delete(0, END)
resultado.set("")
def app():
mo1 = m1.get()
mo2 = m2.get()
d = Distância.get()
G = 6.67430e-11
forca = (G * mo1 * mo2) / (d ** 2)
mensagem = f"A força gravitacional é de {forca} N"
resultado.set(mensagem)
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, 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.35, 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.65, rely=0.65, relwidth=0.25, relheight=0.1)
resultado = StringVar()
resultado_texto = Label(textvariable=resultado,
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9,relheight=0.15)
root.mainloop()
0