Mundo em Python

Compatibilidade de Transfusões

# Dicionário de compatibilidade de transfusão (receber)
compatibilidade_transfusao = {
"A+": ["A+", "A-", "O+", "O-"],
"A-": ["A-", "O-"],
"B+": ["B+", "B-", "O+", "O-"],
"B-": ["B-", "O-"],
"AB+": ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"], # receptor universal
"AB-": ["A-", "B-", "AB-", "O-"],
"O+": ["O+", "O-"],
"O-": ["O-"] # doador universal
} # Dicionário de compatibilidade de transfusão (doar)
compatibilidade_doacao = {
"A+": ["A+", "AB+"],
"A-": ["A+", "A-", "AB+", "AB-"],
"B+": ["B+", "AB+"],
"B-": ["B+", "B-", "AB+", "AB-"],
"AB+": ["AB+"],
"AB-": ["AB+", "AB-"],
"O+": ["O+", "A+", "B+", "AB+"],
"O-": ["O+", "O-", "A+", "A-", "B+", "B-", "AB+", "AB-"]
} from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Compatibilidade de Transfusões") titulo = Label(text="Compatibilidade de Transfusões",
font=("Arial", 28, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05) texto_sub1 = Label(text="Tipo de Sangue: ",
font=("Arial", 18, "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.32) # Dropdown
var = StringVar()
dropDownList = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"]
dropdown = OptionMenu(root, var, *dropDownList)
var.set(dropDownList[0])
dropdown.place(relx=0.45, rely=0.32, relwidth=0.35)
dropdown.config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 18, "bold"))
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 18, "bold")) # Funções
def limpar():
resultado_texto.config(text="") def app():
tipo_receptor = var.get()
pode_receber = compatibilidade_transfusao[tipo_receptor]
pode_doar = compatibilidade_doacao[tipo_receptor] resultado_texto.config(
text=(
f"{tipo_receptor} pode RECEBER de: {', '.join(pode_receber)}\n"
f"{tipo_receptor} pode DOAR para: {', '.join(pode_doar)}"
)
) # Botões
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.53, 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.53, 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.53, relwidth=0.25, relheight=0.1) # Label de resultado
resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3", anchor="w", justify="left")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.22) root.mainloop()
0