from tkinter import *
from tkinter import messagebox as mb
class Quiz:
def __init__(self):
self.perguntas = [
"O paciente está com dificuldade para respirar?",
"O paciente está com dor intensa?",
"O paciente está com hemorragia?",
"O paciente está inconsciente?",
"O paciente está com sinais de AVC (ex. fraqueza, dificuldade de fala)?"
]
self.opcoes_resposta = [
["SIM", "NÃO"],
["SIM", "NÃO"],
["SIM", "NÃO"],
["SIM", "NÃO"],
["SIM", "NÃO"]
]
self.q_no = 0
self.correct = 0
self.data_size = len(self.perguntas)
self.opt_selected = IntVar()
self.display_title()
self.display_question()
self.opts = self.radio_buttons()
self.display_options()
self.buttons()
def display_result(self):
resultado = f"Você pontuou {self.correct} de {self.data_size}."
if self.correct >= 3:
mensagem = "A condição do paciente é grave. Recomendamos atenção médica imediata."
else:
mensagem = "A condição do paciente parece estável. Monitoramento contínuo é recomendado."
mb.showinfo("Resultado da Triagem", f"{resultado}\n{mensagem}")
def check_ans(self, q_no):
return self.opt_selected.get() == 1
def next_btn(self):
if self.check_ans(self.q_no):
self.correct += 1
self.q_no += 1
if self.q_no == self.data_size:
self.display_result()
self.correct = 0
self.q_no = 0
self.display_question()
self.display_options()
def buttons(self):
next_button = Button(root, text="Próximo", command=self.next_btn,
width=10, bg="blue", fg="white", font=("ariel", 16, "bold"))
next_button.place(x=350, y=380)
quit_button = Button(root, text="Sair", command=root.destroy,
width=5, bg="black", fg="white", font=("ariel", 16, " bold"))
quit_button.place(x=700, y=50)
def display_options(self):
val = 0
self.opt_selected.set(0)
for option in self.opcoes_resposta[self.q_no]:
self.opts[val]['text'] = option
val += 1
def display_question(self):
q_no = Label(root, text=self.perguntas[self.q_no], width=60,
font=('ariel', 16, 'bold'), anchor='w')
q_no.place(x=70, y=100)
def display_title(self):
title = Label(root, text="Sistema de Triagem",
width=50, bg="green", fg="white", font=("ariel", 20, "bold"))
title.place(x=0, y=2)
def radio_buttons(self):
q_list = []
y_pos = 150
while len(q_list) < 2:
radio_btn = Radiobutton(root, text=" ", variable=self.opt_selected,
value=len(q_list)+1, font=("ariel", 14))
q_list.append(radio_btn)
radio_btn.place(x=100, y=y_pos)
y_pos += 40
return q_list
root = Tk()
root.geometry("800x450")
root.title("Sistema de Triagem")
quiz = Quiz()
root.mainloop()