Mundo em Python

Velocidade da Luz

from tkinter import *
root = Tk()
root.geometry("500x300")
root.resizable(0, 0)
root.config(bg="#0b4b52")
root.title("Velocidade da Luz ")
titulo = Label(text="Velocidade da Luz",
font=("Arial", "30", "bold"),bg="#0b4b52",fg="#22f2b7")
titulo.place(relx=0.15, rely=0.05)
texto_sub1 = Label(text="Distância (km):",
font=("Arial", "15", "bold"),bg="#0b4b52",fg="#22f2b7")
texto_sub1.place(relx=0.15, rely=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.5, rely=0.3, relwidth=0.38)
def limpar():
Distância_entrada.delete(0, END)
resultado.set("")
def app():
d = Distância.get()
velocidade_da_luz = 299792458
tempo = d / velocidade_da_luz
mensagem = f"O tempo que leva a luz para viajar {d} km:\n {round(tempo,2)} segundos."
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.45, 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.45, 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.45, 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.6, relwidth=0.9,relheight=0.35) root.mainloop()
0