-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
35 lines (27 loc) · 954 Bytes
/
code
File metadata and controls
35 lines (27 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import random
import tkinter as tk
from tkinter import messagebox
# Função para verificar a tentativa do jogador
def verificar_tentativa():
tentativa = int(entry.get())
if tentativa == numero_secreto:
messagebox.showinfo("Resultado", "Parabéns! Você acertou!")
janela.quit()
elif tentativa < numero_secreto:
messagebox.showinfo("Resultado", "Tente um número maior.")
else:
messagebox.showinfo("Resultado", "Tente um número menor.")
# Gera um número aleatório entre 1 e 100
numero_secreto = random.randint(1, 100)
# Cria a janela principal
janela = tk.Tk()
janela.title("Jogo de Adivinhação")
# Cria os componentes da interface
label = tk.Label(janela, text="Tente adivinhar o número:")
label.pack()
entry = tk.Entry(janela)
entry.pack()
button = tk.Button(janela, text="Verificar", command=verificar_tentativa)
button.pack()
# Inicia a execução da interface gráfica
janela.mainloop()