Mundo em Python

Percentagem dos concorrentes

from tkinter import *
root = Tk()
root.geometry("500x600")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Percentagem dos concorrentes") titulo = Label(text="Percentagem dos concorrentes",
font=("Arial", "24", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.03, rely=0.05) Sub1 = Label(text="Candidato 1: ",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
Sub1.place(relx=0.25, rely=0.2) Sub2 = Label(text="Candidato 2: ",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
Sub2.place(relx=0.25, rely=0.3) Sub3 = Label(text="Candidato 3: ",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
Sub3.place(relx=0.25, rely=0.4) Sub4 = Label(text="Candidato 4: ",
font=("Arial", "15", "bold"), bg="#103030", fg="#49e3e3")
Sub4.place(relx=0.25, rely=0.5) Candidato1 = StringVar()
Candidato1_entrada = Entry(textvariable=Candidato1,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Candidato1_entrada.place(relx=0.55, rely=0.2, relwidth=0.25)
Candidato1_entrada.focus() Candidato2 = StringVar()
Candidato2_entrada = Entry(textvariable=Candidato2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Candidato2_entrada.place(relx=0.55, rely=0.3, relwidth=0.25) Candidato3 = StringVar()
Candidato3_entrada = Entry(textvariable=Candidato3,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Candidato3_entrada.place(relx=0.55, rely=0.4, relwidth=0.25) Candidato4 = StringVar()
Candidato4_entrada = Entry(textvariable=Candidato4,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Candidato4_entrada.place(relx=0.55, rely=0.5, relwidth=0.25)
def limpar():
Candidato1_entrada.delete(0,END)
Candidato2_entrada.delete(0,END)
Candidato3_entrada.delete(0,END)
Candidato4_entrada.delete(0,END)
resultado_texto.config(text="")
def app():
try:
c1 =int(Candidato1.get())
c2=int(Candidato2.get())
c3=int(Candidato3.get())
c4=int(Candidato4.get())
total = c1+c2+c3+c4
c1pp=round((c1/total)*100,2)
c2pp = round((c2 / total) * 100, 2)
c3pp = round((c3 / total) * 100, 2)
c4pp = round((c4 / total) * 100, 2)
mensagem = f"Candidato 1: {c1pp} %\tCandidato 2: {c2pp} %\nCandidato 3: {c3pp} %\tCandidato 4: {c4pp} % "

resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Erro na digitação de alguma variável.",fg="red")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.6, 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.6, 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.6, relwidth=0.25, relheight=0.1) resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.73, relwidth=0.9, relheight=0.25)
root.mainloop()
0