Mundo em Python

Quiz usando Radiobutton

from tkinter import Tk, Label, IntVar, Radiobutton

def selecionar():
escolha1 = resposta1.get()
if escolha1 == 3: # Corrigido para comparar com o valor da opção
resultado_texto.config(text="Parabéns! Você acertou!")
else:
resultado_texto.config(text="Ops! Você errou!") root = Tk()
root.geometry("300x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Uma Pergunta usando Radiobutton") titulo = Label(text="Pergunta",
font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.35, rely=0.05) sub1 = Label(text="Qual foi a primeira capital de Portugal?",
font=("Arial", "12", "bold"), bg="#103030", fg="#49e3e3")
sub1.place(relx=0.02, rely=0.15)
resposta1 = IntVar() # Adicionando Radiobuttons com as opções
Radiobutton(root, text="Braga", variable=resposta1, value=0, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.35, rely=0.25)
Radiobutton(root, text="Porto", variable=resposta1, value=1, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.35, rely=0.35)
Radiobutton(root, text="Coimbra", variable=resposta1, value=2, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.35, rely=0.45)
Radiobutton(root, text="Guimarães", variable=resposta1, value=3, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.35, rely=0.55) resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.68, relwidth=0.9, relheight=0.3) root.mainloop()
0