Mundo em Python

Simulador de Quebra de Ovo (usando tkinter)

 


import random
from tkinter import messagebox, Tk, Label, Button, DISABLED, NORMAL
surpresas = [
"Um delicioso ovo de chocolate!",
"Um coelhinho de pelúche!",
"Um vale-brinde para mais chocolate!",
"Uma mensagem especial: 'Feliz Páscoa!'",
"Um bombom recheado!",
"Nada... Esse ovo estava vazio! "
] root = Tk()
root.geometry("700x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title(" Simulador de Quebra de Ovo") titulo = Label(text=" Simulador de Quebra de Ovo",
font=("Arial", 20, "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.13, rely=0.05) resultado_texto = Label(text="", font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
def quebrar_ovo(botao, numero):
resultado_texto.config(text=f"Quebrar o ovo {numero}... ")
botao.config(state=DISABLED) def revelar_surpresa():
surpresa = random.choice(surpresas)
resultado_texto.config(text=f" No ovo {numero}, encontrou: {surpresa}") root.after(2000, revelar_surpresa) def novo():
for botao in botoes:
botao.config(state=NORMAL)
resultado_texto.config(text="")
def sair():
resposta = messagebox.askyesno("Confirmação", " Obrigado por jogar! Feliz Páscoa! \nDeseja sair?")
if resposta:
root.destroy()
botoes = []
for i in range(5):
botao = Button(text=str(i + 1), bd=2, bg='#107db2', fg='white',
font=('verdana', 15, 'bold'), command=lambda b=i: quebrar_ovo(botoes[b], b + 1))
botoes.append(botao) botoes[0].place(relx=0.1, rely=0.35, relwidth=0.15, relheight=0.1)
botoes[1].place(relx=0.3, rely=0.35, relwidth=0.15, relheight=0.1)
botoes[2].place(relx=0.5, rely=0.35, relwidth=0.15, relheight=0.1)
botoes[3].place(relx=0.73, rely=0.35, relwidth=0.15, relheight=0.1)
botoes[4].place(relx=0.4, rely=0.55, relwidth=0.15, relheight=0.1) but_novo = Button(text="Começar Novo", bd=2, bg='green', fg='white',
font=('verdana', 12, 'bold'), command=novo)
but_novo.place(relx=0.08, rely=0.65, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='red', fg='white',
font=('verdana', 12, 'bold'), command=sair)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1) root.mainloop()
0