/
samegameGui.py
82 lines (55 loc) · 2.26 KB
/
samegameGui.py
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
80
81
82
#######################
#asmaa.magdi@gmail.com#
#######################
from tkinter import *
from samegame import SameGame
class samegameGui(Frame):
def __init__(self):
Frame.__init__( self )
self.master.title( "Same Game" )
self.master.rowconfigure( 0, weight = 1 )
self.master.columnconfigure( 0, weight = 1 )
self.grid( sticky = W+E+N+S )
self.buttons = []
r = 10
c = 10
x = 3
self.game = SameGame(r, c, x)
for i in range(0, r):
tmpButtons = []
self.buttons.append(tmpButtons)
for j in range(0, c):
#self.tmpFrame = Frame(self.frame, bd=1, relief=SUNKEN)
#self.tmpFrame.grid(row=i, column=j, sticky=N+E+W+S)
self.buttons[i].append(Button(self, bg = "grey", command = lambda
arg1=i, arg2=j:
self.buttonHandler(arg1, arg2)))
self.buttons[i][j].bind("<Return>", lambda
event, arg1=i, arg2 = j :
self.buttonHandler_a(event, arg1, arg2))
self.buttons[i][j].grid(row = i, column = j, sticky=N+E+W+S)
self.display()
self.master.rowconfigure( 1, weight = 1 )
self.master.columnconfigure( 1, weight = 1 )
def buttonHandler_a(self, event, i, j):
self.buttonHandler(i)
def buttonHandler(self, i, j):
button = self.buttons[i][j]
self.game.click(i, j)
self.display()
def display(self):
colors = ["red", "green", "blue"]
for i in range(0, self.game.r):
for j in range(0, self.game.c):
button = self.buttons[i][j]
c = "grey"
if self.game.grid[i][j] == -1:
pass
#button.grid_forget()
#button.lower(self)
#button.configure(state = 'disabled')
else:
c = colors[self.game.grid[i][j]]
button.configure(activebackground = c)
button.configure(bg = c)
samegameGui().mainloop()