import time
from tkinter import *
class ParkingLot:
def __init__(self, capacity, hourly_rate):
self.capacity = capacity
self.hourly_rate = hourly_rate
self.current_vehicles = {}
self.occupied_spots = 0
def enter_vehicle(self, license_plate):
if self.occupied_spots >= self.capacity:
return "Estacionamento cheio!"
if license_plate in self.current_vehicles:
return f"Veículo {license_plate} já está estacionado."
self.current_vehicles[license_plate] = time.time()
self.occupied_spots += 1
return f"Veículo {license_plate} entrou no estacionamento."
def exit_vehicle(self, license_plate):
if license_plate not in self.current_vehicles:
return f"Veículo {license_plate} não encontrado."
entry_time = self.current_vehicles.pop(license_plate)
self.occupied_spots -= 1
total_time = (time.time() - entry_time) / 3600
fee = round(total_time * self.hourly_rate, 2)
return f"Veículo {license_plate} saiu. Tempo: {total_time:.2f} horas.\nTarifa: €{fee:.2f}."
def parking_status(self):
status = f"Vagas ocupadas: {self.occupied_spots}/{self.capacity}\n"
if not self.current_vehicles:
status += "Estacionamento vazio."
else:
status += "Veículos estacionados:\n"
for plate, entry_time in self.current_vehicles.items():
status += f" {plate} - Entrou às {time.strftime('%H:%M:%S', time.localtime(entry_time))}\n"
return status
root = Tk()
root.geometry("600x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Parque de Estacionamento")
parking_lot = ParkingLot(capacity=10, hourly_rate=2.50)
titulo = Label(
text="Parque de Estacionamento",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.1, rely=0.05)
texto_sub1 = Label(
text="Matrícula:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.2, rely=0.25)
Matricula = StringVar()
Matricula_entrada = Entry(
textvariable=Matricula,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Matricula_entrada.place(relx=0.5, rely=0.26, relwidth=0.35)
resultado_frame = Frame(root, bg="#103030")
resultado_frame.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
resultado_texto = Text(
resultado_frame,
font=("Arial", 12, "bold"),
bg="#cfe2f3",
wrap="word",
state="disabled"
)
resultado_texto.pack(side=LEFT, fill=BOTH, expand=True)
scrollbar = Scrollbar(resultado_frame, orient=VERTICAL, command=resultado_texto.yview)
scrollbar.pack(side=RIGHT, fill=Y)
resultado_texto.config(yscrollcommand=scrollbar.set)
def limpar():
Matricula_entrada.delete(0, END)
resultado_texto.config(state="normal")
resultado_texto.delete(1.0, END)
resultado_texto.config(state="disabled")
def Entrada_veículo():
plate = Matricula.get().strip().upper()
if plate:
mensagem = parking_lot.enter_vehicle(plate)
atualizar_resultado(mensagem)
else:
atualizar_resultado("Por favor, insira uma matrícula válida.")
Matricula_entrada.delete(0, END)
def saida_veículo():
plate = Matricula.get().strip()
if plate:
mensagem = parking_lot.exit_vehicle(plate)
atualizar_resultado(mensagem)
else:
atualizar_resultado("Por favor, insira uma matrícula válida.")
Matricula_entrada.delete(0, END)
def ver_estacionamento():
mensagem = parking_lot.parking_status()
atualizar_resultado(mensagem)
def atualizar_resultado(mensagem):
resultado_texto.config(state="normal")
resultado_texto.insert(END, mensagem + "\n")
resultado_texto.see(END)
resultado_texto.config(state="disabled")
# Botões
but1 = Button(
text="Entrada Veículo",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=Entrada_veículo
)
but1.place(relx=0.05, rely=0.4, relwidth=0.25, relheight=0.1)
but2 = Button(
text="Saída Veículo",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=saida_veículo
)
but2.place(relx=0.35, rely=0.4, relwidth=0.25, relheight=0.1)
but3 = Button(
text="Ver Estacionamento",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=ver_estacionamento
)
but3.place(relx=0.65, rely=0.4, relwidth=0.3, 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.55, 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.55, relwidth=0.25, relheight=0.1)
root.mainloop()
Comentários
Enviar um comentário