pets/visao/tela_principal.py

121 lines
4.1 KiB
Python

import tkinter as tk
from datetime import datetime
from tkinter import font as tkfont
from tkinter import messagebox
from PIL import Image, ImageTk
from persistencia.banco_dados import BancoDeDados
from modelo.pessoa import Pessoa
import os
class TelaPrincipal(tk.Tk):
def __init__(self):
super().__init__()
self.title("Sistema PETS")
self.geometry("900x600")
self.resizable(False, False)
self.configure(bg="#1e1e1e")
self.bd = BancoDeDados()
# if not self.bd.pessoas.listar_todos(): # Adiciona apenas se estiver vazio
# self.bd.pessoas.inserir(Pessoa(1, "Ana Silva"))
# self.bd.pessoas.inserir(Pessoa(2, "Bruno Costa"))
# self.bd.pessoas.inserir(Pessoa(3, "Carlos Dias"))
# self.bd.pessoas.inserir(Pessoa(4, "Daniel Santos"))
self.header = tk.Frame(self, bg="#2c2c2c", height=80)
self.header.pack(side="top", fill="x")
self.header.pack_propagate(False)
script_dir = os.path.dirname(__file__)
logo_path = os.path.join(script_dir, "..", "assets", "images", "logo.png")
logo_pil = Image.open(logo_path)
logo_pil = logo_pil.resize((120, 80), Image.Resampling.LANCZOS)
self.logo_image = ImageTk.PhotoImage(logo_pil)
# O Label agora usa a imagem em vez de texto
self.logo_label = tk.Label(self.header, image=self.logo_image, bg="#2c2c2c")
self.logo_label.pack(side="left", padx=(10, 5))
# -----------------------------
self.relogio_label = tk.Label(self.header, font=("Arial", 12), bg="#2c2c2c", fg="white")
self.relogio_label.pack(side="right", padx=10)
self.atualizar_relogio()
self.menu_lateral = tk.Frame(self, bg="#2c2c2c", width=200)
self.menu_lateral.pack(side="left", fill="y")
self.menu_lateral.pack_propagate(False)
self.area_conteudo = tk.Frame(self, bg="#ccbcbc")
self.area_conteudo.pack(side="right", expand=True, fill="both")
botoes = [
("Início", self.mostrar_inicio),
("Pessoas", self.mostrar_pessoas),
("Pets", self.mostrar_pet),
("Adoções", self.mostrar_adocoes),
("Sair", self.sair),
]
for texto, comando in botoes:
btn = tk.Button(
self.menu_lateral,
text=texto,
command=comando,
bg="#2c2c2c",
fg="white",
activebackground="#3c3c3c",
activeforeground="white",
relief="flat",
borderwidth=0,
highlightthickness=0,
anchor="w",
padx=10,
)
btn.pack(fill="x", pady=2, padx=5)
self.mostrar_inicio()
def atualizar_relogio(self):
agora = datetime.now().strftime("%d-%m-%Y %H:%M:%S")
self.relogio_label.config(text=agora)
self.after(1000, self.atualizar_relogio)
def mostrar_inicio(self):
from visao.frames.frame_inicio import FrameInicio
self.limpar_conteudo()
frame = FrameInicio(self.area_conteudo)
frame.pack(expand=True, fill="both")
def mostrar_pessoas(self):
from visao.frames.frame_pessoa import FramePessoas
self.limpar_conteudo()
frame = FramePessoas(self.area_conteudo, self.bd)
frame.pack(expand=True, fill="both")
def mostrar_pet(self):
from visao.frames.frame_pet import FramePet
self.limpar_conteudo()
frame = FramePet(self.area_conteudo, self.bd)
frame.pack(expand=True, fill="both")
def mostrar_adocoes(self):
from visao.frames.frame_adocao import FrameAdocao
self.limpar_conteudo()
frame = FrameAdocao(self.area_conteudo, self.bd)
frame.pack(expand=True, fill="both")
def limpar_conteudo(self):
for widget in self.area_conteudo.winfo_children():
widget.destroy()
def sair(self):
if messagebox.askyesno("Sair", "Tem certeza que deseja sair?"):
self.destroy()
if __name__ == "__main__":
app = TelaPrincipal()
app.mainloop()