from tkinter import *
import random
root = Tk()
root.geometry("400x300")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Sorteio")
titulo = Label(text="Sorteio",
font=("Arial", "35", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.3, rely=0.05)
texto_sub1 = Label(text="Escolha :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.15, rely=0.35)
numero = StringVar()
numero_entrada = Entry(textvariable=numero,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
numero_entrada.place(relx=0.55, rely=0.38, relwidth=0.35)
numero_entrada.focus()
def limpar():
numero_entrada.delete(0, END)
resultado_texto.config(text="")
def novo_jogo():
global escolha
escolha = random.randint(1, 3)
but1.config(state=NORMAL)
limpar()
def app():
global escolha
try:
n = int(numero.get())
if n not in [1, 2, 3]:
resultado_texto.config(text="Só pode colocar números entre 1 e 3.")
else:
if n == escolha:
resultado_texto.config(text="Parabéns, acertou.\nGanhou doces.")
else:
resultado_texto.config(text="Recebe um balde de água fria.")
but1.config(state=DISABLED)
except ValueError:
resultado_texto.config(text="Por favor, insira um número válido.")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.5, relwidth=0.25, relheight=0.1)
but2 = Button(text="Novo Jogo", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=novo_jogo)
but2.place(relx=0.1, rely=0.68, relwidth=0.25, relheight=0.1)
but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.5, 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.5, relwidth=0.25, relheight=0.1)
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)
novo_jogo()
root.mainloop()