-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatchmaker.py
More file actions
63 lines (54 loc) · 1.82 KB
/
matchmaker.py
File metadata and controls
63 lines (54 loc) · 1.82 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
import random
import time
from tkinter import Tk, Button, DISABLED,messagebox
def close_window(self):
root.destroy()
def show_symbol(x,y):
global first
global previousX, previousY
global moves
global pairs
buttons[x,y]['text']=button_symbols[x,y]
buttons[x,y].update_idletasks()
if first:
previousX=x
previousY=y
first=False
moves=moves+1
elif previousX != x or previousY !=y:
if buttons[previousX, previousY]['text'] != buttons[x,y]['text']:
time.sleep(0.5)
buttons[previousX, previousY]['text'] = ''
buttons[x,y]['text']=''
else:
buttons[previousX, previousY]['comsmand']=DISABLED
buttons[x,y]['command']=DISABLED
pairs=pairs+1
if pairs==len(buttons)/2:
messagebox.showinfo('Matching', 'Number of Moves: ' +
str(moves),command=close_window)
first=True#
root=Tk()
root.title('Matchmaker')
root.resizable(width=False, height=False)
buttons={}
first=True
previousX=0
previousY=0
moves=0
pairs=0
button_symbols={}
symbols=[u"\u2702",u"\u2702",u"\u2705",u"\u2705",u"\u2708",u"\u2708",
u"\u2709",u"\u2709",u"\u270A",u"\u270A",u"\u270B",u"\u270B",
u"\u270C", u"\u270C",u"\u270F",u"\u270F",u"\u2712",u"\u2712",
u"\u2714",u"\u2714",u"\u2716",u"\u2716",u"\u2728",u"\u2728",
u"\2733",u"\2733",u"\2734",u"\2734",u"\2744",u"\2744"]
random.shuffle(symbols)
for x in range(6):
for y in range(5):
button=Button(command=lambda x=x,y=y: show_symbol(x,y), \
width=3,height=3)
button.grid(column=x,row=y)
buttons[x,y]=button
button_symbols[x,y]=symbols.pop()
root.mainloop()