Info
This Little Script works with python 3.4 and Tkinter.
It is only 37 lines long, but very fast and has a small size.
Code:
from tkinter import *;turn=None class pButton(Button): def setty(self):self.state=None def SET(self,what): if what in("X","O"): self.state=what if what=="X":self.config(bg="light green") else:self.config(bg="tomato") self.config(text=self.state) else:print("error") class Main: def __init__(self): self.root=Tk();self.root.title("Tic Tac Toe");self.root.geometry("180x180") self.b=[None,None,None,None,None,None,None,None,None,None] column=0;row=1 for i in range(0,9): self.b[i]=pButton(self.root,text="-") self.b[i].setty() self.b[i].grid(row=row,column=column,pady=5,padx=5) self.b[i].config(width=5,height=2) self.b[i].bind("",lambda event, arg=self.b[i]: self.push(event, arg)) column+=1 if column>2:column=0;row+=1 global turn;turn="X" self.L=Label(self.root);self.L.grid(row=4,column=1);self.L.config(text="{Turn of X}") self.root.mainloop() def push(self,event,pButton): global turn if turn=="X":pButton.SET(turn);turn="O";self.L.config(text="Turn of O") elif turn=="O":pButton.SET(turn);turn="X";self.L.config(text="Turn of X") self.debug() def debug(self): for i in ("X","O"): for x,y,z in [0,1,2],[3,4,5],[6,7,8],[0,3,6],[0,4,8],[2,4,6],[1,4,7],[2,5,8]: if self.b[x].state==i and self.b[y].state==i and self.b[z].state==i:self.L.config(text=i+" wins"),self.L.config(bg="yellow") else:pass main=Main()
Author:Marcin
Language: Python 3.4
Version 0.1
--very easy--