Mundo em Python

Quiz de Contas (usando Tkinter)

from tkinter import *
from tkinter import messagebox
root = Tk()
root.title("Quiz de Contas")
root.geometry("450x650")
root.resizable(0,0)
root.configure(bg="#cfe2f3")
def confirmacao1 ():
r1 = resposta1.get()
if r1 == "2":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 2.'
messagebox.showinfo("Confirmação", mensagem) def confirmacao2 ():
r2 = resposta2.get()
if r2 == "63":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 63.'
messagebox.showinfo("Confirmação", mensagem) def confirmacao3 ():
r3 = resposta3.get()
if r3 == "9":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 9.'
messagebox.showinfo("Confirmação", mensagem) def confirmacao4 ():
r4 = resposta4.get()
if r4 == "7":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 7.'
messagebox.showinfo("Confirmação", mensagem) def confirmacao5 ():
r5 = resposta5.get()
if r5 == "28":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 28.'
messagebox.showinfo("Confirmação", mensagem)
def confirmacao6 ():
r6 = resposta6.get()
if r6 == "8":
mensagem = f'Parabéns! Acertou!!!'
messagebox.showinfo("Confirmação", mensagem)
else:
mensagem = f'Errou! A Resposta correcta é 8.'
messagebox.showinfo("Confirmação", mensagem)
pergunta1_texto = Label(text="Pergunta 1 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta1_texto.place(relx=0.35,rely=0.05) pergunta1 = Label(text="1 + 1 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta1.place(relx=0.05,rely=0.1)
resposta1 = StringVar()
resposta1_entrada= Entry(textvariable=resposta1,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta1_entrada.place(relx=0.2,rely=0.1,relwidth=0.35) but1 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao1)
but1.place(relx=0.6, rely=0.1, relwidth=0.25, relheight=0.05)
pergunta2_texto = Label(text="Pergunta 2 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta2_texto.place(relx=0.35,rely=0.2) pergunta2 = Label(text="9 * 7 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta2.place(relx=0.05,rely=0.25)
resposta2 = StringVar()
resposta2_entrada= Entry(textvariable=resposta2,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta2_entrada.place(relx=0.2,rely=0.25,relwidth=0.35) but2 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao2)
but2.place(relx=0.6, rely=0.25, relwidth=0.25, relheight=0.05)
pergunta3_texto = Label(text="Pergunta 3 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta3_texto.place(relx=0.35,rely=0.35) pergunta3 = Label(text="81 / 9 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta3.place(relx=0.05,rely=0.4)
resposta3 = StringVar()
resposta3_entrada= Entry(textvariable=resposta3,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta3_entrada.place(relx=0.23,rely=0.4,relwidth=0.3) but3 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao3)
but3.place(relx=0.6, rely=0.4, relwidth=0.25, relheight=0.05)
pergunta4_texto = Label(text="Pergunta 4 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta4_texto.place(relx=0.3,rely=0.5) pergunta4 = Label(text="10 - 3 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta4.place(relx=0.05,rely=0.55)
resposta4 = StringVar()
resposta4_entrada= Entry(textvariable=resposta4,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta4_entrada.place(relx=0.23,rely=0.55,relwidth=0.3) but4 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao4)
but4.place(relx=0.6, rely=0.55, relwidth=0.25, relheight=0.05)
pergunta5_texto = Label(text="Pergunta 5 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta5_texto.place(relx=0.3,rely=0.65) pergunta5 = Label(text="4 * 7 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta5.place(relx=0.05,rely=0.7)
resposta5 = StringVar()
resposta5_entrada= Entry(textvariable=resposta5,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta5_entrada.place(relx=0.23,rely=0.7,relwidth=0.3) but5 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao5)
but5.place(relx=0.6, rely=0.7, relwidth=0.25, relheight=0.05) pergunta6_texto = Label(text="Pergunta 6 ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
pergunta6_texto.place(relx=0.3,rely=0.8) pergunta6 = Label(text="14 - 6 = ",bg="#cfe2f3",fg="#f44336",
font=("Arial","14","bold"))
pergunta6.place(relx=0.05,rely=0.85)
resposta6 = StringVar()
resposta6_entrada= Entry(textvariable=resposta6,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
resposta6_entrada.place(relx=0.23,rely=0.85,relwidth=0.3) but6 = Button( text="Confirmar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=confirmacao6)
but6.place(relx=0.6, rely=0.85, relwidth=0.25, relheight=0.05) root.mainloop()
0