-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
81 lines (68 loc) · 3.07 KB
/
Copy pathgui.py
File metadata and controls
81 lines (68 loc) · 3.07 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import warnings
def test(*args):
try:
if(int(userNumber1.get()) < int(userNumber2.get())):
value1 = int(userNumber1.get());
value2 = int(userNumber2.get());
else:
value1 = int(userNumber2.get());
value2 = int(userNumber1.get());
guess = int(userGuess.get())
if(guess == value1 or guess == value2):
tkinter.messagebox.showinfo("", "Acertou!")
root.destroy()
elif(guess > value2):
tkinter.messagebox.showinfo("", "Seu palpite é maior do que o maior dos números!")
global tentativas;
tentativas = tentativas - 1
if(tentativas == 0):
tkinter.messagebox.showinfo("", "Você perdeu!")
root.destroy()
else:
tkinter.messagebox.showinfo("", "Resta(m) " + str(tentativas) + " tentativas")
elif(guess < value1):
tkinter.messagebox.showinfo("", "Seu palpite é menor do que o menor dos números!")
global tentativas;
tentativas = tentativas - 1
if(tentativas == 0):
tkinter.messagebox.showinfo("", "Você perdeu!")
root.destroy()
else:
tkinter.messagebox.showinfo("", "Resta(m) " + str(tentativas) + " tentativas")
else:
tkinter.messagebox.showinfo("", "Seu palpite está entre os números!")
global tentativas;
tentativas = tentativas - 1
if(tentativas == 0):
tkinter.messagebox.showinfo("", "Você perdeu!")
root.destroy()
else:
tkinter.messagebox.showinfo("", "Resta(m) " + str(tentativas) + " tentativas")
except ValueError:
pass
root = Tk()
root.title("Jogo da adivinhação")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
global tentativas;
tentativas = 3;
userNumber1 = StringVar()
userNumber1_entry = ttk.Entry(mainframe, width=7, textvariable=userNumber1, show="*")
userNumber1_entry.grid(column=10, row=1, sticky=(W, E))
userNumber2 = StringVar()
userNumber2_entry = ttk.Entry(mainframe, width=7, textvariable=userNumber2, show="*")
userNumber2_entry.grid(column=10, row=2, sticky=(W, E))
userGuess = StringVar();
userGuess_entry = ttk.Entry(mainframe, width=7, textvariable=userGuess)
userGuess_entry.grid(column=10, row=3, sticky=(W, E))
ttk.Button(mainframe, text="Advinhar", command=test).grid(column=10, row=4, sticky=W)
ttk.Label(mainframe, text="Jogador 1, digite aqui o primeiro número a ser advinhado:").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="Jogador 1, digite aqui o segundo número a ser advinhado:").grid(column=3, row=2, sticky=W)
ttk.Label(mainframe, text="Jogador 2, digite aqui o seu palpite:").grid(column=3, row=3, sticky=W)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
mainloop();