-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
667 lines (569 loc) · 28 KB
/
__main__.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
## DISCLAIMER: This was my first ever game after learning the basic of python so the current .py file is not optimized
__version__ = '0.0.2'
import platform
import random as rnd
from tkinter import *
from tkinter import ttk
from tkinter.font import Font
from tkinter.messagebox import *
from pygame.mixer import init, music
from Tk_Loop import GuiLoop
from Titlebar import TitleBar
from TkExtra import Canvas, grid
import tkinter.font as font
import tkmacosx as tkm
# Common button options
button_options = dict(
borderless=1,
takefocus=0,
activebackground=('white', 'black'),
overbackground='#3d4246',
font=('Avenir'),
)
class FrameBody(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self)
self.option_add("*Font", ('Avenir'))
self.py = init()
self.tb = TitleBar(self, "TicTacToe", False) # if enabled use self.geometry("500x325+300+200")
self.tb.icon('./assets/icon.icns')
self.tb.dark_mode()
self.Load = music.load('dummy.mp3')
self.Move = True
self.off = True
self.Restarting = True
self._Turn = 'h'
self.Round = 1
self.BgBlack = "black"
self.BgWhite = "white"
self.difficulty = "unbeatable"
self.PlScr = 0
self.CpScr = 0
self.Effect = True
self.EffectCount=0
self.EffectCurrent = None
self.EffectLoop=0
self.configure(highlightbackground=self.BgWhite,highlightcolor=self.BgWhite,highlightthickness=3)
self.title('TicTacToe')
self.resizable(False,False)
self.geometry("500x325+300+200")
self.configure(bg=self.BgBlack)
self.options = Frame(self, bg=self.BgBlack, width=150)
self.options.config(highlightbackground=self.BgWhite,highlightcolor=self.BgWhite,highlightthickness=1)
self.options.grid_propagate(1)
self.options.pack(side=LEFT, fill=Y)
self._Grid(root=self.options, row=15, col=3)
self.Score=Label(self.options, text='Score', fg=self.BgWhite, bg=self.BgBlack)
self.Score.config(font=Font(size=35, underline=True, family='Savoye LET', slant='italic'))
self.Score.grid(row=0, columnspan=4, padx=10)
self.Player=Label(self.options, text="Player",fg=self.BgWhite, bg=self.BgBlack)
self.Player.grid(row=1, column=0, padx=10, sticky=SW)
self.Computer=Label(self.options, text="Computer",fg=self.BgWhite, bg=self.BgBlack)
self.Computer.grid(row=1, column=3, padx=10, sticky=SE)
self.PlayerScore=Label(self.options, text='0',fg=self.BgWhite, bg=self.BgBlack)
self.PlayerScore.grid(row=2, column=0, padx=20, sticky=NSEW)
self.ComputerScore=Label(self.options, text='0',fg=self.BgWhite, bg=self.BgBlack)
self.ComputerScore.grid(row=2, column=3, padx=20, sticky=NSEW)
self.DiffLB1 = Label(self.options,fg=self.BgWhite, bg=self.BgBlack)
self.DiffLB1.config(text="Difficulty:")
self.DiffLB1.grid(row=9, columnspan=4,padx=10,sticky=S)
self.DiffLB2 = Label(self.options,fg=self.BgWhite, bg=self.BgBlack)
self.DiffLB2.config(text=self.difficulty.capitalize())
self.DiffLB2.config(font=Font(weight="bold"))
self.DiffLB2.grid(row=10,columnspan=4,padx=10,sticky=N)
self.RoundLB=Label(self.options, text=("Round: {}".format(self.Round)),fg=self.BgWhite, bg=self.BgBlack)
self.RoundLB.grid(row=5,columnspan=4,padx=10)
self._Data = {0:None, 1:None, 2:None, 3:None, 4:None, 5:None, 6:None, 7:None, 8:None}
self.Draw = _drawings(self,background=self.BgBlack)
self.Draw.pack(side=LEFT)
self.Ai=Bot(self, difficulty=self.difficulty)
self.Setting = Settings(self)
self.bind("<Button-1>", self.Turn)
self.AniLoop = GuiLoop(self, self.RandomHexCode, speed=100)
self.Win_ChkLoop = GuiLoop(self, self.win_check, speed=100)
def Sound_Effect(self, state=True):
if state and self.off:
music.play()
else: return
def RandomHexCode(self, whatever=None):
r = lambda: rnd.randint(0,255)
color = ('#%02X%02X%02X' % (r(),r(),r()))
self.Score.configure(fg=color)
self.Setting.headinglb['fg'] = color
for i in (1,2,3,4): self.Draw.itemconfig(i,fill=color)
self.config(highlightcolor=color)
def _Grid(self, root, row, col):
for y in range(col):
Grid.columnconfigure(root, y, weight=1)
for x in range(row):
Grid.rowconfigure(root, x, weight=1)
def Turn(self, evt=None):
if self.Restarting:
if self.Draw.Human(evt=evt):
self.after(615, lambda: self.Ai.Move())
def Effects(self):
Stop = False
self.Move = False
if self.EffectCount <= 5:
if self.Effect:
self.Draw.itemconfig(self.EffectCurrent,state='hidden')
self.Effect=False
else:
self.Draw.itemconfig(self.EffectCurrent,state='normal')
self.Effect=True
self.EffectCount+=1
else:
self.EffectCount = 0
self.after_cancel(self.EffectLoop)
self.Move=True
Stop = True
if not Stop: self.EffectLoop=self.after(100,self.Effects)
def win_check(self):
for i in self.Ai._Combo:
if self._Data[i[0]]=='X' and self._Data[i[1]]=='X' and self._Data[i[2]]=='X':
self.CpScr+=1
self.ComputerScore.configure(text=str(self.CpScr))
for x,y in self.Draw._LineDic.items():
if i == y: self.Draw.itemconfig(x,state='normal')
self.Move=False
self.Restarting = False
self.Win_ChkLoop.Pause()
self.Restart(win=True)
return True
if self._Data[i[0]]=='O' and self._Data[i[1]]=='O' and self._Data[i[2]]=='O':
self.PlScr+=1
self.PlayerScore.configure(text=str(self.PlScr))
for x,y in self.Draw._LineDic.items():
if i == y: self.Draw.itemconfig(x, state='normal')
self.Move=False
self.Restarting = False
self.Win_ChkLoop.Pause()
self.Restart(win=True)
return True
if None not in self._Data.values():
self.Win_ChkLoop.Pause()
self.Restart()
return False
def Restart(self, win = False):
def Reset():
self.Round+=1
self.RoundLB.configure(text=("Round: {}".format(self.Round)))
self.Move=True
self.Effect = True
self.Restarting = True
self.EffectCount=0
self.EffectCurrent = None
self.EffectLoop=0
self._Data = {0:None, 1:None, 2:None, 3:None, 4:None, 5:None, 6:None, 7:None, 8:None}
self.Draw.destroy()
del self.Ai
# self.update()
self.Draw = _drawings(self,background=self.BgBlack,
highlightbackground=self.BgWhite,highlightcolor=self.BgWhite)
self.Draw.pack(side=LEFT)
self.Ai=Bot(self, difficulty=self.difficulty)
self.DiffLB2.config(text=self.difficulty.capitalize())
self.Win_ChkLoop.Play()
if None not in self._Data.values(): self.after(1500, Reset)
if win: self.after(1500, Reset)
class _drawings(Canvas):
def __init__(self, master, *args, **kwargs):
Canvas.__init__(self, master, kwargs)
self.master = master
self.configure(highlightthickness=1)
self.config(width=350, height=300)
self.start = None
# Lines
self.create_line(125, 40, 125, 260, fill= self.master.BgWhite, width=4)
self.create_line(215, 40, 215, 260, fill= self.master.BgWhite, width=4)
self.create_line(50, 105, 290, 105, fill= self.master.BgWhite, width=4)
self.create_line(50, 185, 290, 185, fill= self.master.BgWhite, width=4)
self.L012=self.create_line(70, 70, 270, 70, fill= self.master.BgWhite, width=4, state='hidden')
self.L345=self.create_line(70, 145, 270, 145, fill= self.master.BgWhite, width=4, state='hidden')
self.L678=self.create_line(70, 220, 270, 220, fill= self.master.BgWhite, width=4, state='hidden')
self.L147=self.create_line(170, 60, 170, 240, fill= self.master.BgWhite, width=4, state='hidden')
self.L036=self.create_line( 85, 60, 85, 240, fill= self.master.BgWhite, width=4, state='hidden')
self.L258=self.create_line(255, 60, 255, 240, fill= self.master.BgWhite, width=4, state='hidden')
self.L048=self.create_line( 80, 60, 260, 230, fill= self.master.BgWhite, width=4, state='hidden')
self.L246=self.create_line(260, 60, 80, 230, fill= self.master.BgWhite, width=4, state='hidden')
self._LineDic={
self.L012 : [0,1,2],
self.L345 : [3,4,5],
self.L678 : [6,7,8],
self.L147 : [1,4,7],
self.L036 : [0,3,6],
self.L258 : [2,5,8],
self.L048 : [0,4,8],
self.L246 : [2,4,6],
}
def Click(self, x, y):
if x<120 and y<100 and x> 50 and y> 40: return 50+8, 40-8, 0
if x<210 and y<100 and x>130 and y> 40: return 135+8, 40-8, 1
if x<290 and y<100 and x>220 and y> 40: return 220+8, 40-8, 2
if x<120 and y<190 and x> 50 and y>120: return 50+8, 115-8, 3
if x<210 and y<190 and x>130 and y>120: return 135+8, 115-8, 4
if x<290 and y<190 and x>220 and y>120: return 220+8, 115-8, 5
if x<120 and y<260 and x> 50 and y>192: return 50+8, 192-8, 6
if x<210 and y<260 and x>130 and y>192: return 135+8, 192-8, 7
if x<290 and y<260 and x>220 and y>192: return 220+8, 192-8, 8
return False
def Human(self, evt=None):
if self.Click(evt.x, evt.y) and self.master.Move:
x,y,p=self.Click(evt.x, evt.y)
if self.master._Data[p] == None:
L = self.create_text(x,y,text="◯",font=Font(size=60),fill= self.master.BgWhite,anchor=NW)
self.master.Sound_Effect()
self.master.EffectCurrent=L
self.master.Effects()
self.master._Data.update({p:"O"})
return True
class Bot(object):
def __init__(self, master, difficulty=None, *args, **kwargs):
self.master = master
self.Goonce = True
self._Data = master._Data
self.Draw = master.Draw
self.diff = difficulty
self._TryBlock = { (1,6) : 0,
(1,8) : 2,
(7,2) : 8,
(7,0) : 6,
(3,8) : 6,
(3,2) : 0,
(5,0) : 2,
(5,6) : 8 }
self._TryBlock2 = { (5,7) : 0,
(1,5) : 6,
(1,3) : 8,
(3,7) : 2 }
self._AlreadyMoved=False
self._Combo = ( [0, 1, 2],[0, 3, 6],[0, 4, 8],
[1, 4, 7],[2, 5, 8],[2, 4, 6],
[3, 4, 5],[6, 7, 8] )
self._Poisiton = ( ( 50+11, 40-2, 0),
(135+11, 40-2, 1),
(220+11, 40-2, 2),
( 50+11, 115-2, 3),
(135+11, 115-2, 4),
(220+11, 115-2, 5),
( 50+11, 192-2, 6),
(135+11, 192-2, 7),
(220+11, 192-2, 8) )
self._Cornors = (0, 6, 8, 2)
self._Sides = (1, 3, 5, 7)
self._Move = 0
def Move(self):
if None in self._Data.values() and self.master.Move and self.master.Restarting:
self.master.Sound_Effect()
if self.diff=="unbeatable" or self.diff=='hard':
if self.Smart_Move():
self._AlreadyMoved = True
return True
if self.diff=="unbeatable":
if self.Block2():
self._AlreadyMoved = True
return True
if self.diff=="unbeatable" or self.diff=="medium" or self.diff=="hard" or self.diff=="easy":
if self.Aggressive_Move():
self._AlreadyMoved = True
return True
if self.diff=="unbeatable" or self.diff=="medium" or self.diff=="hard":
if self.Defensive_Move():
self._AlreadyMoved = True
return True
if self.diff=="unbeatable" or self.diff=="hard" or self.diff=="medium":
if self.Block():
self._AlreadyMoved = True
return True
if self.diff=="unbeatable" or self.diff=="medium" or self.diff=="hard" or self.diff=="easy":
if self.Just_Move():
self._AlreadyMoved = True
return True
else: return False
def Smart_Move(self):
if self._Data[4] == None :
x,y,p = self._Poisiton[4]
L = self.Draw.create_text(x,y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({4:"X"})
return True
return False
def Aggressive_Move(self):
for x in self._Combo:
if self._Data[x[0]] == "X" and self._Data[x[1]] == "X" and self._Data[x[2]] == None:
X,Y,p = self._Poisiton[x[2]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
elif self._Data[x[1]] == "X" and self._Data[x[2]] == "X" and self._Data[x[0]] == None:
X,Y,p = self._Poisiton[x[0]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
elif self._Data[x[2]] == "X" and self._Data[x[0]] == "X" and self._Data[x[1]] == None:
X,Y,p = self._Poisiton[x[1]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
def Defensive_Move(self):
for x in self._Combo:
if self._Data[x[0]] == "O" and self._Data[x[1]] == "O" and self._Data[x[2]] == None:
X,Y,p = self._Poisiton[x[2]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
elif self._Data[x[1]] == "O" and self._Data[x[2]] == "O" and self._Data[x[0]] == None:
X,Y,p = self._Poisiton[x[0]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
elif self._Data[x[2]] == "O" and self._Data[x[0]] == "O" and self._Data[x[1]] == None:
X,Y,p = self._Poisiton[x[1]]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
def Block(self):
SidTmp = []
for Con in self._Cornors:
if self._Data[Con] == "O" and self._Data[4] == "X":
for x in self._Sides:
if self._Data[x] == None: SidTmp.append(x)
choice = rnd.choice(SidTmp)
X,Y,p = self._Poisiton[choice]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
return True
def Block2(self):
tmp=list(self._Data.values())
tmp = tmp.count(None)
for i,j in self._TryBlock.items():
if (self._Data[i[0]]=="O") and (self._Data[i[1]]=="O") and \
(self.Goonce) and (self._Data[j]==None) and (tmp>=6):
X,Y,p = self._Poisiton[j]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
self.Goonce=False
return True
def Just_Move(self):
ConTmp = []
SidTmp = []
tmp = True
for x in self._Cornors:
for i,j in self._TryBlock2.items():
if self._Data[i[0]]=="O" and self._Data[i[1]]=="O" \
and self._Data[x]==None and x!=j and self.diff=="unbeatable":
ConTmp.append(x)
tmp=False
break
for x in self._Cornors:
if self._Data[x]==None and tmp:
ConTmp.append(x)
if ConTmp == []:
for x in self._Sides:
if self._Data[x]==None:
SidTmp.append(x)
choice = rnd.choice(SidTmp)
X,Y,p = self._Poisiton[choice]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
SidTmp.clear()
return True
else:
choice = rnd.choice(ConTmp)
X,Y,p = self._Poisiton[choice]
L = self.Draw.create_text(X,Y,text="╳",font=Font(size=50),fill= self.master.BgWhite,anchor=NW)
self.master.EffectCurrent=L
self.master.Effects()
self._Data.update({p:"X"})
ConTmp.clear()
return True
return False
class Settings(Toplevel):
def __init__(self, master, *args, **kwargs):
Toplevel.__init__(self, master)
self._Settings = False
self._Sound = True
self._ColorEff = True
self.master = master
self.BgBlack = master.BgBlack
self.BgWhite = master.BgWhite
grid(self, 6, 3)
self.config(bg=self.BgBlack,highlightbackground= self.BgWhite,
highlightcolor= self.BgWhite,highlightthickness=1)
self.wm_overrideredirect(1)
if platform.system() == 'Darwin':
self.wm_overrideredirect(0)
self.attributes('-alpha', 0.95)
self.withdraw()
# Settings
self.SettingLB = tkm.Button(self.master.options,
text='Settings', fg=self.BgWhite,
bg='black', command=self.Settings,
**button_options)
self.SettingLB.grid(row=14, columnspan=4, ipadx=10, ipady=2, pady=2)
self.headinglb = Label(self, text='Settings Menu')
self._Note = Label(self, text="Note: The difficulty will change next round.")
self._Note.config(bg="black", fg="white", font=Font(size=9))
self.headinglb.config(bg="black", fg="white", font=Font(size=35, underline=True, family='Savoye LET', slant='italic'))
self.headinglb.grid(row=0, columnspan=3, sticky='nsew', pady=(5,10))
self._Note.grid(row=5, columnspan=3)
self.ImpLabels()
def ImpLabels(self):
self.LightM = tkm.Button(self, text='☀', bg='black', fg='white', width=40, pady=2, command=self.Light_Mode, **button_options)
self.LightM.grid(row=1, column=0,)
self.DarkM = tkm.Button(self,text="☾",bg="black", fg="white", width=40, pady=2, command=self.Dark_Mode, **button_options)
self.DarkM.grid(row=2, column=0)
self.Easy = tkm.Button(self,text="Easy", bg="black", fg="white", **button_options)
self.Easy['command'] = lambda: self.Difficulty('easy')
self.Easy.grid(row=1, column=1, sticky='nsew', padx=10, pady=2)
self.Medium = tkm.Button(self,text="Medium", bg="black", fg="white", **button_options)
self.Medium['command'] = lambda: self.Difficulty('medium')
self.Medium.grid(row=2, column=1,sticky='nsew', padx=10, pady=2)
self.Hard = tkm.Button(self, text="Hard", bg="black", fg="white", **button_options)
self.Hard['command'] = lambda: self.Difficulty('hard')
self.Hard.grid(row=3, column=1, sticky='nsew', padx=10, pady=2)
self.Unbeatable = tkm.Button(self,text="Unbeatable",bg="black",fg="white", **button_options)
self.Unbeatable['command'] = lambda: self.Difficulty('unbeatable')
self.Unbeatable.grid(row=4, column=1, sticky='nsew', padx=10, pady=2)
self.Close = tkm.Button(self,text="Close", bg="black", fg="white", pady=5, **button_options)
self.Close['command'] = self.Settings
self.Close.grid(row=6, pady=(10, 5), padx=50, columnspan=3, sticky='nsew')
self.Sound = tkm.Button(self,text="♬ ✔", bg="black", fg="white", **button_options)
self.Sound['command'] = self.Sound_Mode
self.Sound.grid(row=3, column=0, ipadx=10, ipady=2, pady=2)
self.CrlEff = tkm.Button(self,text="Color ✔", bg="black", fg="white", **button_options)
self.CrlEff['command'] = self.ColorEffects
self.CrlEff.grid(row=4, column=0, ipadx=10, ipady=2, pady=2)
self.Help = tkm.Button(self,text="ⓘ",bg="black", fg="white", width=40, **button_options)
self.Help['command'] = self._Help
self.Help.grid(row=1, column=2, ipadx=10, ipady=2, pady=2)
def Settings(self, evt=None):
if not self._Settings:
geo = "400"+"x"+"300"+"+"+str(self.master.winfo_rootx()+50)+'+'+str(self.master.winfo_rooty()+12)
self.lift()
self.geometry(geo)
self.deiconify()
self.update_idletasks()
self.grab_set()
self.Difficulty(self.master.difficulty)
self._Settings = True
else:
self.withdraw()
self.master.grab_set()
self.update_idletasks()
self._Settings = False
def Light_Mode(self, evt=None):
self.master.tb.light_mode()
self.config(bg='white',highlightbackground="black",highlightcolor="black")
self.master.config(bg='white',highlightbackground="black",highlightcolor="black")
self.master.options.config(bg='white',highlightbackground="black",highlightcolor="black")
for i in self.master.options.winfo_children():i.config(fg="black", bg="white")
for i in self.winfo_children(): i.config(fg="black", bg="white")
for i in range(1,25): self.master.Draw.itemconfig(i, fill='black')
self.master.Draw.config(bg='white',highlightbackground="black",highlightcolor="black")
self.SettingLB.bind("<Leave>", lambda evt:self.SettingLB.config(bg="white"))
self.LightM.bind("<Leave>", lambda evt:self.LightM.config(bg="white"))
self.DarkM.bind("<Leave>", lambda evt:self.DarkM.config(bg="white"))
self.Easy.bind("<Leave>", lambda evt:self.Easy.config(bg="white"))
self.Medium.bind("<Leave>", lambda evt:self.Medium.config(bg="white"))
self.Hard.bind("<Leave>", lambda evt:self.Hard.config(bg="white"))
self.Unbeatable.bind("<Leave>", lambda evt:self.Unbeatable.config(bg="white"))
self.Sound.bind("<Leave>", lambda evt:self.Sound.config(bg="white"))
self.Close.bind("<Leave>", lambda evt:self.Close.config(bg="white"))
self.CrlEff.bind("<Leave>", lambda evt:self.CrlEff.config(bg="white"))
self.Help.bind("<Leave>", lambda evt:self.Help.config(bg="white"))
self.master.BgBlack = "white"
self.master.BgWhite = "black"
def Dark_Mode(self, evt=None):
self.master.tb.dark_mode()
self.config(bg='black',highlightbackground="white",highlightcolor="white")
self.master.config(bg='black',highlightbackground="white",highlightcolor="white")
self.master.options.config(bg='black',highlightbackground="white",highlightcolor="white")
for i in self.master.options.winfo_children(): i.config(fg="white", bg="black")
for i in self.winfo_children(): i.config(fg="white", bg="black")
for i in range(1,25): self.master.Draw.itemconfig(i, fill='white')
self.master.Draw.config(bg='black',highlightbackground="white",highlightcolor="white")
self.SettingLB.bind("<Leave>", lambda evt:self.SettingLB.config(bg="black"))
self.LightM.bind("<Leave>", lambda evt:self.LightM.config(bg="black"))
self.DarkM.bind("<Leave>", lambda evt:self.DarkM.config(bg="black"))
self.Easy.bind("<Leave>", lambda evt:self.Easy.config(bg="black"))
self.Medium.bind("<Leave>", lambda evt:self.Medium.config(bg="black"))
self.Hard.bind("<Leave>", lambda evt:self.Hard.config(bg="black"))
self.Unbeatable.bind("<Leave>", lambda evt:self.Unbeatable.config(bg="black"))
self.Sound.bind("<Leave>", lambda evt:self.Sound.config(bg="black"))
self.Close.bind("<Leave>", lambda evt:self.Close.config(bg="black"))
self.CrlEff.bind("<Leave>", lambda evt:self.CrlEff.config(bg="black"))
self.Help.bind("<Leave>", lambda evt:self.Help.config(bg="black"))
self.master.BgBlack = "black"
self.master.BgWhite = "white"
def Sound_Mode(self, evt=None):
if self._Sound:
self.Sound.config(text="♬ ✕")
self.master.off = False
self._Sound=False
else:
self.Sound.config(text="♬ ✔")
self.master.off = True
self._Sound=True
def Difficulty(self, dif):
for i in (self.Easy, self.Medium, self.Hard, self.Unbeatable):
if i['text'].lower() == dif:
i['state'] = 'active'
else:
i['state'] = 'normal'
self.master.difficulty = dif
def ColorEffects(self, evt=None):
if self._ColorEff:
self.master.AniLoop.Pause()
self.CrlEff.config(text="Color ✕")
if self.cget('bg')=="black":
for i in (1,2,3,4): self.master.Draw.itemconfig(i,fill="white")
self.master.Score.config(fg="white", bg="black")
self.headinglb.config(fg="white", bg="black")
self.master.config(highlightcolor="white")
else:
for i in (1,2,3,4): self.master.Draw.itemconfig(i,fill="black")
self.master.Score.config(fg="black", bg="white")
self.master.config(highlightcolor="black")
self.headinglb.config(fg="black", bg="white")
self._ColorEff = False
else:
if self.cget('bg')=="black":
self.master.config(highlightcolor="white")
self.master.Score.config(fg="white", bg="black")
else:
self.master.config(highlightcolor="black")
self.master.Score.config(fg="black", bg="white")
self.CrlEff.config(text="Color ✔")
self.master.AniLoop.Play()
self._ColorEff = True
def _Help(self, evt=None):
showinfo("Help",message="""
TIC-TAC-TOE
Version 0.0.2
Make (7 Dec'18)
Developer: Saad Mairaj
Saadmairaj@yahoo.in
""")
if __name__ == "__main__":
App = FrameBody()
App.mainloop()