from tkinter import * # Inicializando a janela principal
root = Tk()
root.geometry("500x300")
root.resizable(0, 0)
root.title("Simulador de Maioria Parlamentar")
root.config(bg="#d9ead3") # Função de seleção e cálculo dos deputados
def seleccionar():
soma = 0
if (PS.get()):
soma += 78
if (PSD.get()):
soma += 80
if (Chega.get()):
soma += 50
if (IL.get()):
soma += 8
if (BE.get()):
soma += 5
if (L.get()):
soma += 4
if (PAN.get()):
soma += 1
if (PCP.get()):
soma += 4
monitor.config(text=f"Total: {soma} deputados") # Verificar se a maioria foi alcançada
if soma >= 116:
monitor1.config(text="Maioria Atingida!", fg="green")
else:
monitor1.config(text="Sem maioria", fg="red") # Título
texto2 = Label(root, text="Simulador de Maioria Parlamentar", font=("Arial", "20", "bold"), bg="#d9ead3", fg="#bf9000")
texto2.place(relx=0.05, rely=0.05) # Variáveis para os Checkbuttons (partidos)
PS = IntVar()
PSD = IntVar()
Chega = IntVar()
IL = IntVar()
BE = IntVar()
L = IntVar()
PAN = IntVar()
PCP = IntVar() # Checkbuttons para selecionar partidos
Checkbutton(root, text="PS", variable=PS, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.05, rely=0.3)
Checkbutton(root, text="PSD", variable=PSD, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.28, rely=0.3)
Checkbutton(root, text="Chega", variable=Chega, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.5, rely=0.3)
Checkbutton(root, text="IL", variable=IL, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.75, rely=0.3)
Checkbutton(root, text="BE", variable=BE, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.05, rely=0.5)
Checkbutton(root, text="Livre", variable=L, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.28, rely=0.5)
Checkbutton(root, text="PAN", variable=PAN, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.5, rely=0.5)
Checkbutton(root, text="PCP", variable=PCP, onvalue=1, offvalue=0, command=seleccionar, font=("Arial", "12", "bold"),
bg="#d9ead3", fg="#bf9000").place(relx=0.75, rely=0.5) # Label para mostrar o total de deputados
monitor = Label(root, bg="#d9ead3", font=("Arial", "12", "bold"), fg="blue")
monitor.place(relx=0.1, rely=0.75) # Label dinâmica para mostrar se há maioria ou não
monitor1 = Label(root, text="Sem maioria", bg="#d9ead3", font=("Arial", "12", "bold"), fg="red")
monitor1.place(relx=0.45, rely=0.75) # Informação estática sobre o número de deputados necessário para a maioria
monitor2 = Label(root, text="Para ter maioria, precisa de 116 deputados", bg="#d9ead3", font=("Arial", "12", "bold"), fg="blue")
monitor2.place(relx=0.1, rely=0.9) # Loop principal
root.mainloop()
# Versão melhorada
from tkinter import * # Inicializando a janela principal
root = Tk()
root.geometry("900x400")
root.title("Simulador de Maioria Simples")
root.config(bg="#d9ead3")
# Função de seleção e cálculo dos votos
def seleccionar():
votos_a_favor = 0
votos_contra = 0
# Verificar o voto de cada partido
if voto_PS.get() == 1: # A favor
votos_a_favor += 78
elif voto_PS.get() == -1: # Contra
votos_contra += 78
if voto_PSD.get() == 1:
votos_a_favor += 80
elif voto_PSD.get() == -1:
votos_contra += 80
if voto_Chega.get() == 1:
votos_a_favor += 50
elif voto_Chega.get() == -1:
votos_contra += 50
if voto_IL.get() == 1:
votos_a_favor += 8
elif voto_IL.get() == -1:
votos_contra += 8
if voto_BE.get() == 1:
votos_a_favor += 5
elif voto_BE.get() == -1:
votos_contra += 5
if voto_L.get() == 1:
votos_a_favor += 4
elif voto_L.get() == -1:
votos_contra += 4
if voto_PAN.get() == 1:
votos_a_favor += 1
elif voto_PAN.get() == -1:
votos_contra += 1
if voto_PCP.get() == 1:
votos_a_favor += 4
elif voto_PCP.get() == -1:
votos_contra += 4
# Mostrar o total de votos a favor e contra
monitor.config(text=f"Votos a favor: {votos_a_favor}\n | Votos contra: {votos_contra}") # Verificar se a maioria simples foi atingida
if votos_a_favor > votos_contra:
monitor1.config(text="Proposta Aprovada (Maioria Simples)", fg="green")
else:
monitor1.config(text="Proposta Rejeitada", fg="red")
# Título
texto2 = Label(root, text="Simulador de Maioria Simples", font=("Arial", "25", "bold"), bg="#d9ead3", fg="#bf9000")
texto2.place(relx=0.15, rely=0.05) # Variáveis para armazenar o voto de cada partido
voto_PS = IntVar(value=0)
voto_PSD = IntVar(value=0)
voto_Chega = IntVar(value=0)
voto_IL = IntVar(value=0)
voto_BE = IntVar(value=0)
voto_L = IntVar(value=0)
voto_PAN = IntVar(value=0)
voto_PCP = IntVar(value=0)
# Função auxiliar para criar os Radiobuttons
def criar_opcoes(partido, variable, y):
Label(root, text=partido, font=("Arial", 12, "bold"), bg="#d9ead3", fg="#bf9000").place(relx=0.05, rely=y) # A favor, Contra, Abstenção
Radiobutton(root, text="A favor", variable=variable, value=1, command=seleccionar, bg="#d9ead3",
font=("Arial", 10)).place(relx=0.3, rely=y)
Radiobutton(root, text="Contra", variable=variable, value=-1, command=seleccionar, bg="#d9ead3",
font=("Arial", 10)).place(relx=0.5, rely=y)
Radiobutton(root, text="Abstenção", variable=variable, value=0, command=seleccionar, bg="#d9ead3",
font=("Arial", 10)).place(relx=0.7, rely=y)
# Criando as opções de voto para cada partido
criar_opcoes("PS", voto_PS, 0.2)
criar_opcoes("PSD", voto_PSD, 0.3)
criar_opcoes("Chega", voto_Chega, 0.4)
criar_opcoes("IL", voto_IL, 0.5)
criar_opcoes("BE", voto_BE, 0.6)
criar_opcoes("Livre", voto_L, 0.7)
criar_opcoes("PAN", voto_PAN, 0.8)
criar_opcoes("PCP", voto_PCP, 0.9) # Label para mostrar o total de votos a favor e contra
monitor = Label(root, bg="#d9ead3", font=("Arial", "12", "bold"), fg="blue")
monitor.place(relx=0.83, rely=0.2) # Label dinâmica para mostrar se a proposta foi aprovada ou rejeitada
monitor1 = Label(root, text="Proposta Rejeitada", bg="#d9ead3", font=("Arial", "12", "bold"), fg="red")
monitor1.place(relx=0.83, rely=0.35) # Informação estática sobre a votação
monitor2 = Label(root, text="Para aprovar,"
"\nprecisa de mais votos\n a favor do que contra\n"
"(Maioria Simples)", bg="#d9ead3",
font=("Arial", "12", "bold"), fg="blue")
monitor2.place(relx=0.8, rely=0.75) # Loop principal
root.mainloop()