Mundo em Python

Densidade Populacional

from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#14477a")
root.title("Densidade Populacional") titulo = Label(text="Densidade Populacional",
font=("Arial", "25", "bold"), bg="#14477a", fg="#1be3e0")
titulo.place(relx=0.03, rely=0.05) texto_sub1 = Label(text="População Total:",
font=("Arial", "15", "bold"), bg="#14477a", fg="#1be3e0")
texto_sub1.place(relx=0.07, rely=0.2) texto_sub2 = Label(text="Área Terrestre (km²):",
font=("Arial", "15", "bold"), bg="#14477a", fg="#1be3e0")
texto_sub2.place(relx=0.07, rely=0.4) População_Total = IntVar()
População_Total_entrada = Entry(textvariable=População_Total,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
População_Total_entrada.place(relx=0.6, rely=0.2, relwidth=0.3) area_terrestre_km2 = IntVar()
area_terrestre_km2_entrada = Entry(textvariable=area_terrestre_km2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
area_terrestre_km2_entrada.place(relx=0.6, rely=0.4, relwidth=0.3)
def limpar():
area_terrestre_km2_entrada.delete(0, END)
População_Total_entrada.delete(0, END)
def app():
pop_total = População_Total.get()
area = area_terrestre_km2.get()
densidade_populacional = pop_total / area
resultado.set(f'Densidade Populacional:\n {densidade_populacional:.2f} pessoas/km²')
but1 = Button(text="Verificar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.5, 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.5, 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.5, 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.7, relwidth=0.9, relheight=0.2) root.mainloop()
0