from tkinter import *
import matplotlib.pyplot as plt
root = Tk()
root.geometry("500x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular crescimento populacional")
titulo = Label(text="Calcular crescimento populacional",
font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="População Inicial:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.25)
texto_sub2 = Label(text="Taxa crescimento (em %) :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.4)
texto_sub3 = Label(text="Anos :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.48, rely=0.55)
População_Inicial = StringVar()
População_Inicial_entrada = Entry(textvariable=População_Inicial,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
População_Inicial_entrada.place(relx=0.65, rely=0.26, relwidth=0.33)
Taxa_crescimento = StringVar()
Taxa_crescimento_entrada = Entry(textvariable=Taxa_crescimento,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Taxa_crescimento_entrada.place(relx=0.65, rely=0.41, relwidth=0.33)
anos = StringVar()
anos_entrada = Entry(textvariable=anos,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
anos_entrada.place(relx=0.65, rely=0.56, relwidth=0.33)
def limpar():
anos_entrada.delete(0, END)
Taxa_crescimento_entrada.delete(0, END)
População_Inicial_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
p = int(População_Inicial.get())
a = int(anos.get())
t = float(Taxa_crescimento.get()) / 100
populations = [p]
for year in range(1, a + 1):
p = p * (1 + t)
populations.append(p)
# Plotting the data
plt.figure(figsize=(10, 6))
plt.plot(range(a + 1), populations, marker='o', color='b')
plt.title('Simulador de Crescimento Populacional')
plt.xlabel('Anos')
plt.ylabel('População')
plt.grid(True)
plt.show()
resultado_texto.config(text=f"População após {a} anos: {int(populations[-1])}")
except ValueError:
resultado_texto.config(text="Por favor, insira valores numéricos válidos.")
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)
root.mainloop()
Comentários
Enviar um comentário