from tkinter import Tk, Label, IntVar, Radiobutton, Button
import random
def is_prime(n):
if n <= 1:
return False
elif n <= 3:
return True
elif n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def selecionar():
escolha1 = resposta1.get()
if (escolha1 == 1 and is_prime(escolha_aleatoria)) \
or (escolha1 == 0 and not is_prime(escolha_aleatoria)):
resultado_texto.config(text="Parabéns! Você acertou!")
else:
resultado_texto.config(text="Ops! Você errou!")
def novo_jogo():
global escolha_aleatoria
escolha_aleatoria = random.randint(0, 30)
escolha_número.config(text=escolha_aleatoria)
resultado_texto.config(text="")
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Jogo do número Primo")
titulo = Label(text="Jogo do número Primo",
font=("Arial", "20", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, 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()
Radiobutton(root, text="Primo", variable=resposta1, value=1, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.15, rely=0.4)
Radiobutton(root, text="Não Primo", variable=resposta1, value=0, command=selecionar,
font=("Arial", "12"), bg="#103030", fg="white").place(relx=0.5, rely=0.4)
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.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.55, relwidth=0.25, 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()
Comentários
Enviar um comentário