from tkinter import Tk, Label, IntVar, Radiobutton, Button
import random
def par_impar(numero):
return numero % 2 == 0
def novo_jogo():
global escolha_aleatoria
escolha_aleatoria = random.randint(0, 30)
escolha_número.config(text=escolha_aleatoria)
resultado_texto.config(text="")
resposta1.set(-1) # Resetar a escolha para evitar seleção prévia
# Ativar os botões de rádio
par_button.config(state="normal")
impar_button.config(state="normal")
def selecionar():
escolha = resposta1.get()
if (escolha == 1 and par_impar(escolha_aleatoria)) or \
(escolha == 0 and not par_impar(escolha_aleatoria)):
resultado_texto.config(text="Parabéns! Você acertou!")
else:
resultado_texto.config(text="Ops! Você errou!")
# Desativar os botões de rádio após o jogador fazer uma escolha
par_button.config(state="disabled")
impar_button.config(state="disabled")
root = Tk()
root.geometry("300x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Jogo do número Par ou Ímpar")
titulo = Label(text="Jogo do número Par ou Ímpar",
font=("Arial", "14", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
escolha_aleatoria = random.randint(0, 30)
escolha_número = Label(text=escolha_aleatoria,
font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
escolha_número.place(relx=0.45, rely=0.2)
resposta1 = IntVar()
par_button = Radiobutton(root, text="PAR", variable=resposta1, value=1, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white")
par_button.place(relx=0.15, rely=0.35)
impar_button = Radiobutton(root, text="ÍMPAR", variable=resposta1, value=0, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white")
impar_button.place(relx=0.5, rely=0.35)
but1 = Button(text="Novo Jogo", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=novo_jogo)
but1.place(relx=0.1, rely=0.55, relwidth=0.35, 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.6, rely=0.55, relwidth=0.3, relheight=0.1)
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()