Mundo em Python

Ligação de Respostas

from tkinter import *

root = Tk()
root.geometry("800x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Ligação de Respostas") titulo = Label(text="Ligação de Respostas",
font=("Arial", "36", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.15, rely=0.05)
texto_sub1 = Label(text="1. Cardume",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25) texto_sub2 = Label(text="2. Alcateia",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.4) texto_sub3 = Label(text="3. Frota",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.05, rely=0.55)
texto_sub4 = Label(text="a) Conjunto de Navios",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub4.place(relx=0.55, rely=0.25) texto_sub5 = Label(text="b) Conjunto de Peixe",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub5.place(relx=0.55, rely=0.4) texto_sub6 = Label(text="c) Conjunto de Lobos",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub6.place(relx=0.55, rely=0.55)
resposta1 = StringVar()
resposta1_entrada = Entry(textvariable=resposta1,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
resposta1_entrada.place(relx=0.35, rely=0.26, relwidth=0.1) resposta2 = StringVar()
resposta2_entrada = Entry(textvariable=resposta2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
resposta2_entrada.place(relx=0.35, rely=0.41, relwidth=0.1) resposta3 = StringVar()
resposta3_entrada = Entry(textvariable=resposta3,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
resposta3_entrada.place(relx=0.35, rely=0.56, relwidth=0.1)
def limpar():
resposta1_entrada.delete(0, END)
resposta2_entrada.delete(0, END)
resposta3_entrada.delete(0, END)
resultado_texto.config(text="")
resposta1_entrada.config(bg="white")
resposta2_entrada.config(bg="white")
resposta3_entrada.config(bg="white") def validar_respostas():
r1 = resposta1.get().strip().lower()
r2 = resposta2.get().strip().lower()
r3 = resposta3.get().strip().lower()
corretas = {
"1": "b", # Cardume -> Conjunto de Peixe
"2": "c", # Alcateia -> Conjunto de Lobos
"3": "a" # Frota -> Conjunto de Navios
}
erros = 0
if r1 == "b":
resposta1_entrada.config(bg="lightgreen")
else:
resposta1_entrada.config(bg="red")
erros += 1

if r2 == "c":
resposta2_entrada.config(bg="lightgreen")
else:
resposta2_entrada.config(bg="red")
erros += 1

if r3 == "a":
resposta3_entrada.config(bg="lightgreen")
else:
resposta3_entrada.config(bg="red")
erros += 1

# Resultado final
if erros == 0:
resultado_texto.config(text="Parabéns! Todas as ligações estão corretas.", fg="green")
else:
resultado_texto.config(text=f"Existem {erros} respostas incorretas. Tente novamente!", fg="red") botao_validar = Button(text="Validar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=validar_respostas)
botao_validar.place(relx=0.1, rely=0.7, relwidth=0.25, relheight=0.1) botao_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
botao_limpar.place(relx=0.4, rely=0.7, relwidth=0.25, relheight=0.1) botao_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
botao_sair.place(relx=0.7, rely=0.7, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.85, relwidth=0.9, relheight=0.1) root.mainloop()
0