from tkinter import *
import re
def validar_tempo(tempo):
padrao = r"^\d+:[0-5]\d\.\d{3}$"
return re.match(padrao, tempo)
def tempo_para_segundos(tempo):
minutos, resto = tempo.split(":")
segundos = float(resto)
return int(minutos) * 60 + segundos
def app():
melhor_tempo_str = Melhor_tempo_Q1.get()
tempo_piloto_str = Tempo_piloto.get()
if not validar_tempo(melhor_tempo_str):
resultado_texto.config(text="Formato do melhor tempo inválido! Use ex: 1:40.000")
return
if not validar_tempo(tempo_piloto_str):
resultado_texto.config(text="Formato do tempo do piloto inválido! Use ex: 1:45.200")
return
melhor_tempo = tempo_para_segundos(melhor_tempo_str)
tempo_piloto = tempo_para_segundos(tempo_piloto_str)
limite = melhor_tempo * 1.07
minutos_limite = int(limite // 60)
segundos_limite = limite % 60
limite_formatado = f"{minutos_limite}:{segundos_limite:06.3f}"
if tempo_piloto <= limite:
resultado_texto.config(text=f"✅ Dentro da regra dos 107%\nLimite: {limite_formatado}")
else:
resultado_texto.config(text=f"❌ Fora da regra dos 107%\nLimite: {limite_formatado}")
def limpar():
Tempo_piloto_entrada.delete(0, END)
Melhor_tempo_Q1_entrada.delete(0, END)
resultado_texto.config(text="")
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Regra dos 107%")
titulo = Label(text="Regra dos 107% da F1", font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.28, rely=0.05)
texto_sub1 = Label(text="Melhor tempo da Q1 (ex: 1:40.000):", font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3)
texto_sub2 = Label(text="Tempo do piloto (ex: 1:40.000):", font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.12, rely=0.5)
Melhor_tempo_Q1 = StringVar()
Melhor_tempo_Q1_entrada = Entry(textvariable=Melhor_tempo_Q1, font=("Arial", 12, "bold"), bg="white", fg="blue",
justify='center')
Melhor_tempo_Q1_entrada.place(relx=0.63, rely=0.33, relwidth=0.35)
Melhor_tempo_Q1_entrada.focus()
Tempo_piloto = StringVar()
Tempo_piloto_entrada = Entry(textvariable=Tempo_piloto, font=("Arial", 12, "bold"), bg="white", fg="blue",
justify='center')
Tempo_piloto_entrada.place(relx=0.63, rely=0.51, relwidth=0.35)
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()