0% found this document useful (0 votes)
104 views39 pages

Minor Project Report

This document provides a summary of a minor project report for developing a Brain Game (Tic Tac Toe game) using Python. The report includes an introduction to tic tac toe, objectives of developing the game, analysis of existing manual system and proposed computerized system, system specifications, software description, project description, code execution details, use case diagram, coding methods, limitations and future plans. The proposed system aims to develop a graphical user interface based tic tac toe game to overcome limitations of manual paper-based system and provide an interactive gaming experience to users.

Uploaded by

Akash Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views39 pages

Minor Project Report

This document provides a summary of a minor project report for developing a Brain Game (Tic Tac Toe game) using Python. The report includes an introduction to tic tac toe, objectives of developing the game, analysis of existing manual system and proposed computerized system, system specifications, software description, project description, code execution details, use case diagram, coding methods, limitations and future plans. The proposed system aims to develop a graphical user interface based tic tac toe game to overcome limitations of manual paper-based system and provide an interactive gaming experience to users.

Uploaded by

Akash Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

1|Page

Brain Game
In python 3
2|Page

MINOR PROJECT REPORT

PYTHON (MCAM2107L)
(Brain Game)
Programming Lab - VI
A report submitted to Punjabi University, PATIALA in
partial fulfilment of the requirement for the award of
degree course
In
MASTER OF COMPUTER APPLICATIONS (MCA)
(2022-2023)
3rd SEMESTER
(DEPARTMENT OF COMPUTER SCIENCE)

Submitted to: Submitted by:


Dr. Jaswinder Singh Name: Akashdeep
(Assistant Professor) Uni.Roll No:
Name: Dimpy Rewaria
Uni.Roll No:

BABA FARID COLLEGE, BATHINDA


3|Page

DECLARATION

We affirm that the minor project work titled “BRAIN GAME” being

submitted in partial fulfilment for the award of Master Degree of Computer

Science is the original work carried out by us. It has not formed the part of

any other project work submitted for award of any degree or diploma,

either in this or any other University.

(Signature of the Candidate) (Signature of the Candidate)

AKASHDEEP DIMPY REWARIA


UID : 21108053 UID : 21108067
Session: 2022-2023 Session: 2022-2023
4|Page

CERTIFICATE

I here by certify that the work presented in this report entitled "BRAIN GAME"

submitted in the partial fulfilment of the requirement for the award of degree of

Master Computer Applications from the department of Computer Science, Baba

Farid College, BATHINDA is an authentic record of my own work.

Project Guide
Dr. Jaswinder Singh

Dr. Jaspreet Kaur (HOD)


BFGI, Bathinda
Signature with Date __________
5|Page

ACKNOWLEDGEMENT

I take this opportunity to express my gratitude to our guide, Assistant


Professor DR. Jaswinder Singh, Dept. of Computer Science for his
valuable suggestion and noble guidance at all stages of this project
study.

I also express our sincere thanks to our other for giving us consistent
encouragement, support and valuable guidance throughout the course of
the project without their stable guidance this project would not have been
achieved.

I am also thankful to the authority of “BABA FARID COLLEGE” for their


support in our project.

Our due thanks to our HEAD OF DEPARTMENT MAM, Dr. Jaspreet Kaur, for
his support throughout the course.

Finally, we would like to thank all those friends who are involved directly
and indirectly in completion of our project.
6|Page

CONTENT

Sr. No. TITLE Page No.

1. Abstract 6

2. Introduction 7

3. System Analysis 8 to 10

4. System Specification 11

5. Software Description 12 to 15

6. Project Description 16 to 22

7. Code Execution 23 to 27

8. Use Case Diagram 28

9. Methods 29

10. Coding 30 to 37

11. Limitations 38

12. Future Plan 38

13. Reference 38
7|Page

1. ABSTRACT

The game TIC TAC TOE had an early variant which began in the first
century in the Roman Empire. During that time, it was called Terni Lapilli
where the players only had three pieces and had to move around the
empty spaces to play. The actual game of TIC TAC TOE could be
traced back to ancient Egypt. The game was also known during that time
as ʖ Three Men's Morrisʗ. The first reference to Noughts and crosses was
made in 1864 in a British novel called Can You Forgive Her. For many
years the game was referred to as noughts and crosses but was changed
in the 20th century by the United States to TIC TAC TOE.

The purpose of this documentation is to capture all the requirements by


which the user can play a game of tic-tac-toe in Graphical User
Interface as well as they can develop a logic that what is actually
happening.

`
8|Page

2. INTRODUCTION
2.1 OBJECTIVE:

One of the most universally played childhood games is TIC


TAC TOE. An interactive TIC TAC TOE game is developed
where two players will be able to play against each other in a
suitable GUI by using proper mouse movements. This game
will start by showing a simple display, prompt the user for a
move and then prints the new board. The board looks like a
large hash symbol (#) with nine slots that can each contain an
X, an O, or a blank. There are two players, the X player and
the O player. By default, player1 (the O player) takes the
initiative. The game will end in two situations: a win, when one
player gets three in a row, horizontally, vertically or diagonally.
A draw, when there are no remaining places to choose and
neither of them has won. Here are some rules for the game:

 The player with symbol ʒO or ʓX goes first

 Players alternate placing X s and O s on the board until either

 one player has three in a row, horizontally, vertically or diagonally; or

 all nine squares are filled.

 The player who can draw three X s or three O s in a row wins.

 If all nine squares are filled and none of the players have three in a
row, the game is a draw.
9|Page

3 SYSTEM ANALYSIS
INTRODUCTION:

Analysis can be defined by breaking up of any whole so as to


find out their nature, working functionalities etc. It defines
design as to make preliminary sketches of; to sketch a pattern
or outline for planning. To plan and carry out especially by
artistic arrangement or in a skilful wall. System analysis and
design can be characterized as a set of techniques and
processes, a community of interests, a culture and intellectual
orientation.

The various tasks in system analysis phase including the


following:
 Understanding Application
 Project Planning
 Project Scheduling
 Performing Trade Studies
 Performing Cost Benefit Analysis
 Recommending Alternative Solutions
 Supervising, Installing, Maintaining the system

This system allows the user to feel the taste of playing the
game endlessly. First design the class which will keeps track
various functions like board structure, pixel selection, grid
selection, canvas structure, click recognition, gameplay, game
over screen etc. And according to the moves played by the
players this project will display the result in very attractive
format.
10 | P a g e

3.1 EXISTING SYSTEM:

The Existing system is a simple game to play with paper and


pencil between two people. Here the whole process will be
carried out in the hand-written format making nine square grids,
placing X’s and O’s and checking for the winner. This process
will repeat every time. So, it will be a tedious job to draw a nine
square grid every time with paper and pencil. The human effort
is more here. Along with that the retrieval of the information is
not easy as the records are maintained in the hand-written
papers. This application requires correct feed on input into the
respective field. Suppose the wrong inputs are entered, then
the whole process is to be done again. So, the users find it
difficult to use.
11 | P a g e

3.2 PROPOSED SYSTEM:

To overcome the drawbacks of the existing system, the


proposed system has been evolved. This project aims to
reduce the paper work and saving time to generate accurate
results from the player’s perspective. The system provides with
the best Graphical User Interface. The efficient reports can be
generated by using this proposed system.

3.2.1 ADVANTAGES OF PROPOSED SYSTEM


 The game has been made user friendly with proper use
of graphical interface.
 The user can play as many games without any interpretation.
 It is highly reliable, approximate result from user.
 The game has been made as a thorough expert system.
 The players can win the game, draw the game or will lose the
game.
 It is a good brain exercise for all age group people.
12 | P a g e

4. SYSTEM SPECIFICATION

HARDWARE REQUIREMENT [minimum requirement]:

Minimum RAM: - 1GB


Minimum Hard Disk: - 128GB
Processor: - Intel Core i3 7th Generation or above

SOFTWARE REQUIREMENT [minimum requirement]:

Operating System: - Support for both LINUX and WINDOWS users


Back End: - Python 3.10.2 Interpreter
Front End Language: - Python3
Front Design: - Tkinterface
13 | P a g e

5. SOFTWARE DESCRIPTION
PYTHON 3.10.2 IDLE 2022

IDLE stands for Integrated Development and Learning


Environment is an integrated development environment for
python. It has been bundled with the default implementation of
the language since 1.5.2b.1. It is packaged as an optional part
of the python packaging with many Linux distribution. It is
completely written in python3 and Tkinter GUI toolkit. IDLE is
intended to be a simple IDE and suitable for beginners as well
as advanced users. To that end it is cross platform and avoids
feature clutter. The features provided by the IDLE includes:

5.1.1 Python shell with syntax highlighting.

5.1.2 Integrated debugger with stepping, persistent


breakpoints and call stack visibility.

5.1.3 Multi-window text editor with syntax highlighting,


auto completion, smart indenting etc.

5.2 DEVELOPMENT TOOLS AND TECHNOLOGIES

5.2.1 PYTHON 3:

Python is a general purpose interpreted, interactive,


object-oriented, and high-level programming language. It
was created by Guido Van Rossum during 1985-1990.
Like Perl, Python source code is also available under the
GNU General Public License (GPL). Python is named
after a TV show called ‘‘Monty Python’s Flying Circus’’.
14 | P a g e

Python 3.0(also called “Python 3000” or “Py3K”) was


released in December 3, 2008. The latest version of
python accumulated new and redundant ways to
program the same task, Python 3.6 had an emphasis on
removing duplicative constructs and modules, in keeping
with “There should be one and preferable only one –
obvious way to do it”. Python’s dynamic typing
encourage the programmer to write a code that is clear,
well structured as well as easy to understand. The
features of dynamic typing are:
 Types are bound to values but not to variables.
 Function and method lookup is done at runtime.
 Values are inspect-able.
 There is an interactive interpreter, more than one, in fact.
 You can list the methods supported by any given object.

Because code is automatically compiled to byte code and


executed, Python is suitable for use as a scripting
language, Web application implementation language etc.
Because of its strong structuring constructs (nested code
blocks, functions, classes, modules and packages) and
its consistent use of objects and OOP, Python enables
you to write clear and logical code for small and large
projects.
15 | P a g e

5.2 GUI (GRAPHICAL USER INTERFACE):

Our goal in this article is to provide you with an


introductory of GUI programming. In order to learn the
GUI programming, you must first understand a few core
aspects of GUI. So let’s begin the discussion. The
primary GUI toolkit will be using Tk, Python’s default GUI.
We’ll access Tk from its python interface called Tkinter.
It is not the latest and greatest nor does it have the most
robust set of GUI building blocks, but it is fairly simple to
use and using it, you can build GUI’s that run on most
platforms. Setting up GUI application is similar to how an
artist produces a painting. Conventio- nally there is a
single canvas onto which the artist must put all the work.
In GUI programming a toplevel root windowing object
contains all of the little windowing objects that will be a
part of your GUI application. These can be text labels,
buttons, list boxes etc. These individual little GUI
components are known as widgets. Top level windows
are those that show up stand alone as part of your
application. Interestingly, you can have more than one
top level window for your GUI, but only one of them
should be your root window.
16 | P a g e

The top level window can be created using this:


import tkinter
top=tkinter.Tk()

The object returned by tkinter.Tk( ) is usually referred to


as the root window. Within this window you can place
multiple component pieces together to form your GUI. Tk
has three geometry managers that help with positioning
your widget set.

5.2.1.1 Placer: You provide the size of the widgets and


locations to place them, this manager then places
them for you.
5.2.1.2 Packer: It packs widgets into the correct places.
5.2.1.3 Grid: It is used to specify GUI widget placement
based on grid coordinates.

Now once the packer has determined the sizes and


alignments of your widgets, it will then place them on the
screen for you. When all the widgets are in place we
instruct the application to infinite main loop. In Tkinter the
code that does it is:

Tkinter.mainloop()

This is normally the last piece of sequential code your program


runs.
17 | P a g e

6. PROJECT DESCRIPTION

Objectives:
Our project name is Tic-Tac-Toe game. This game is very popular
and is fairly simple by itself. It is actually a two player game. In this
game, there is a board with n x n squares. In our game, it is 3 x 3
squares.
The goal of Tic-Tac-Toe is to be one of the players to get three same
symbols in a row - horizontally, vertically or diagonally - on a 3 x 3
grid.

1. Overview:

This game can be played in a 3x3 grid (shown in the figure 2.1) .The
game can be played by two players. There are two options for
players:

(a) Human (b) Computer

Figure: 2.1

2.1 Players:

For the option human, both the players are human and for the option
computer, the first player is human and the second player is
computer.

2.2 Theory of Game:


18 | P a g e

A player can choose between two symbols with his opponent, usual
games use “X”and “O”. If first player choose “X” then the second player
have to play with “O” and vice versa.

A player marks any of the 3x3 squares with his symbol (may be “X” or
“O”) and his aim is to create a straight line horizontally or vertically or
diagonally with two intensions:

a) Create a straight line before his opponent to win the game.

b) Restrict his opponent from creating a straight line first.

In case logically no one can create a straight line with his own symbol,
the game results a tie.

Hence there are only three possible results – a player wins, his
opponent (human or computer) wins or it’s a tie.
19 | P a g e

1 2 3

4 5 6

7 8 9

Figure: 2.2

If any player is able to draw three Xs or three Os in the following


combinations then that player wins. The combinations are:

a) 1, 2, 3 b) 4, 5, 6

c) 7, 8, 9 d) 1, 4, 7

e) 2, 5, 8 f) 3, 6, 9

h) 1, 5, 9 i) 3, 5, 7
20 | P a g e

2. Core Logic - AI:

There are two core logics in this game – when both players are human,
and when one is computer. Suppose the player use X and the
computer use O . The logic used for the AI is as follows:

3.1 First move:


a) If the center is free, get the center. (Figure: 3.1)
b) Otherwise, get any of the corners. (Figure: 3.2)

X
O O

X
O

Figure: Figure: 3.2


3.1

3.2 Second move:

a) Block user from winning. (Figure: 3.3)


b) Option for winning by applying the following logic:
If the center is occupied by user, get any of th
(Figure:
3.4)
21 | P a g e

X X O O
O O
O X

X
O

Figure: 3.3 Figure: 3.4

Otherwise, the following cases happen:

Case 1:

X
O
O
O O
X
O

Figure: 3.5

If any situation arises like the figure 3.5 then the computer sets its
symbol any one of the position among 2, 4, 6 and 8.
22 | P a g e

Case 2:

X X X

4 O 6 4 O 6 4 O 6

X X X

Figure: 3.6 Figure: 3.7 Figure: 3.8

If any situation arises like the figure 3.6 or figure 3.7 or figure 3.8
then the computer sets its symbol at any position among 4 and 6.
23 | P a g e

Case 3:

2 2 2

O X X O X X O

X 8 8 8 X

Figure: 3.9 Figure: 3.10 Figure: 3.11

If any situation arises like the figure 3.9 or figure 3.10 or figure 3.11 then the
computer sets its symbol at any position among 2 and 8.

Case 4:

1 X 3 1 X 3

O X X O

7 9 7 9

Figure: 3.12 Figure: 3.13

1 3 1 3

X O O X

7 X 9 7 X 9

Figure: 3.14 Figure: 3.15

If any situation arises like the figure 3.12 or figure 3.13 or figure 3.14 or
3.15 then the computer sets its symbol at any position among 1, 3, 7 and 9.
24 | P a g e

3.3 Third and fourth move:


a) Option for winning. (Figure: 3.16)
b) Block user from winning. (Figure: 3.17)
c) Randomly play a move. (Figure: 3.18)

O X O

X O X O

X X X
O
Figure: 3.16 Figure: 3.17

X X O

O O X

X
O
Figure: 3.18

3. Core Logic - Humans:


For each move, check whether any 3 combination is occupied by any
player and display the winner accordingly.
25 | P a g e

7. CODE EXECUTION

import tkinter.messagebox
from tkinter import*

root =Tk()
root.geometry("1350x750+0+0")

root.title("Tic Tac Toe")


root.configure(background='Pink')

Tops =Frame(root,bg='Pink',pady=2, width=1350, height=100,


relief=RIDGE)
Tops.grid(row=0, column=0)

lblTitle=Label(Tops,font=('arial',50,'bold'),text="Advanced Tic Tac Toe


Game", bd=21, bg='Pink',fg='Cornsilk',justify=CENTER)
lblTitle.grid(row=1,column=0)

MainFrame = Frame(root, bg='Powder Blue', bd=10, width=1350,


height=600, relief=RIDGE)
MainFrame.grid(row=1,column=0)

LeftFrame= Frame(MainFrame, bd=10, width=750, height=500, pady=2,


padx=10, bg="Pink", relief=RIDGE)
LeftFrame.pack(side=LEFT)

RightFrame = Frame(MainFrame, bd=10, width=560,


height=500,padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame.pack(side=RIGHT)

RightFrame1 = Frame(RightFrame, bd=10, width=560, height=200,


padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame1.grid(row=0,column=0)

RightFrame2 = Frame(RightFrame, bd=10, width=560, height=200,


padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame2.grid(row=1,column=0)
26 | P a g e

Function: def NewGame():


reset()
PlayerX.set(0)
PlayerO.set(0)

lblPlayerX=Label(RightFrame1, font=('arial',40,'bold'), text="Player X


:",padx=2,pady=2, bg="Pink")
lblPlayerX.grid(row=0, column=0,sticky=W)
txtPlayerX=Entry(RightFrame1, font=('arial',40,'bold'), bd=2, fg =
'black', textvariable= PlayerX, width=14,
justify=LEFT).grid(row=0,column=1)

lblPlayerO=Label(RightFrame1, font=('arial',40,'bold'), text="Player O


:",padx=2,pady=2, bg="Pink")
lblPlayerO.grid(row=1, column=0,sticky=W)
txtPlayerO=Entry(RightFrame1, font=('arial',40,'bold'), bd=2, fg =
'black', textvariable= PlayerO, width=14,
justify=LEFT).grid(row=1,column=1)

btnReset=Button(RightFrame2, text="Reset", font=('arial',40,'bold'),


height = 1, width=20, command = reset)
btnReset.grid(row=2, column=0, padx=6, pady=11)

btnNewGame=Button(RightFrame2, text="New Game",


font=('arial',40,'bold'), height=1, width=20, command = NewGame)
btnNewGame.grid(row=3, column=0, padx=6, pady=10)

button1 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button1))
button1.grid(row=1, column=0, sticky = S+N+E+W)
27 | P a g e

button2 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button2))
button2.grid(row=1, column=1, sticky = S+N+E+W)

button3 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button3))
button3.grid(row=1, column=2, sticky = S+N+E+W)

button4 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button4))
button4.grid(row=2, column=0, sticky = S+N+E+W)

button5 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button5))
button5.grid(row=2, column=1, sticky = S+N+E+W)

button6 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button6))
button6.grid(row=2, column=2, sticky = S+N+E+W)

button7 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button7))
button7.grid(row=3, column=0, sticky = S+N+E+W)

button8 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button8))
button8.grid(row=3, column=1, sticky = S+N+E+W)

button9 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button9))
button9.grid(row=3, column=2, sticky = S+N+E+W)
28 | P a g e
29 | P a g e

8. USE CASE DIAGRAM

Start Game

Player 1
moves

Player 2
moves

Check the
result

Player 1 Player 2

Play again
30 | P a g e

9. Methods

The methods we used in our program are as follows:

1. def checker(buttons)

2. def scorekeeper()

3. def reset():

4. def NewGame()
31 | P a g e

10. Coding
import tkinter.messagebox
from tkinter import*

root =Tk()
root.geometry("1350x750+0+0")
root.title("Tic Tac Toe")
root.configure(background='Pink')

Tops =Frame(root,bg='Pink',pady=2, width=1350, height=100,


relief=RIDGE)
Tops.grid(row=0, column=0)

lblTitle=Label(Tops,font=('arial',50,'bold'),text="Advanced Tic Tac Toe


Game", bd=21, bg='Pink',fg='Cornsilk',justify=CENTER)
lblTitle.grid(row=1,column=0)

MainFrame = Frame(root, bg='Powder Blue', bd=10, width=1350,


height=600, relief=RIDGE)
MainFrame.grid(row=1,column=0)

LeftFrame= Frame(MainFrame, bd=10, width=750, height=500, pady=2,


padx=10, bg="Pink", relief=RIDGE)
LeftFrame.pack(side=LEFT)

RightFrame = Frame(MainFrame, bd=10, width=560,


height=500,padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame.pack(side=RIGHT)

RightFrame1 = Frame(RightFrame, bd=10, width=560, height=200,


padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame1.grid(row=0,column=0)

RightFrame2 = Frame(RightFrame, bd=10, width=560, height=200,


padx=10, pady=2, bg="Pink", relief=RIDGE)
RightFrame2.grid(row=1,column=0)

PlayerX=IntVar()
PlayerO=IntVar()
32 | P a g e

PlayerX.set(0)
PlayerO.set(0)

button = StringVar()
click = True

def checker(buttons):
global click
if buttons["text"] == " " and click == True:
buttons["text"] = "X"
click = False
scorekeeper()
elif buttons["text"] == " " and click == False:
buttons["text"] = "O"
click = True
scorekeeper()

def scorekeeper():

if(button1["text"]=="X" and button2["text"]=="X" and


button3["text"]=="X"):
button1.configure(background ="powder blue")
button2.configure(background ="powder blue")
button3.configure(background ="powder blue")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button4["text"]=="X" and button5["text"]=="X" and


button6["text"]=="X"):
button4.configure(background ="Red")
button5.configure(background ="Red")
button6.configure(background ="Red")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")
33 | P a g e

if(button7["text"]=="X" and button8["text"]=="X" and


button9["text"]=="X"):

button7.configure(background ="Pink")
button8.configure(background ="Pink")
button9.configure(background ="Pink")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button3["text"]=="X" and button5["text"]=="X" and


button7["text"]=="X"):
button3.configure(background ="Pink")
button5.configure(background ="Pink")
button7.configure(background ="Pink")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button1["text"]=="X" and button5["text"]=="X" and


button9["text"]=="X"):
button1.configure(background ="Purple")
button5.configure(background ="Purple")
button9.configure(background ="Purple")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button1["text"]=="X" and button4["text"]=="X" and


button7["text"]=="X"):
button1.configure(background ="Yellow")
button4.configure(background ="Yellow")
button7.configure(background ="Yellow")
n = float(PlayerX.get())
score = (n + 1)
34 | P a g e

PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button2["text"]== "X" and button5["text"] == "X" and


button8["text"]== "X"):
button2.configure(background ="Pink")
button5.configure(background ="Pink")

button8.configure(background ="Pink")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button3["text"]=="X" and button6["text"]=="X" and


button9["text"]=="X"):
button3.configure(background ="powder blue")
button6.configure(background ="powder blue")
button9.configure(background ="powder blue")
n = float(PlayerX.get())
score = (n + 1)
PlayerX.set(score)
tkinter.messagebox.showinfo("Winner X", "You have just won a
game")

if(button1["text"]=="O" and button2["text"]=="O" and


button3["text"]=="O"):
button1.configure(background ="Orange")
button2.configure(background ="Orange")
button3.configure(background ="Orange")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")
35 | P a g e

if(button4["text"]=="O" and button5["text"]=="O" and


button6["text"]=="O"):
button4.configure(background ="Blue")
button5.configure(background ="Blue")
button6.configure(background ="Blue")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

if(button7["text"]=="O" and button8["text"]=="O" and


button9["text"]=="O"):
button7.configure(background ="Green")

button8.configure(background ="Green")
button9.configure(background ="Green")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

if(button3["text"]=="O" and button5["text"]=="O" and


button7["text"]=="O"):
button3.configure(background ="Pink")
button5.configure(background ="Pink")
button7.configure(background ="Pink")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

if(button1["text"]=="O" and button5["text"]=="O" and


button9["text"]=="O"):
button1.configure(background ="Orange")
button5.configure(background ="Orange")
button9.configure(background ="Orange")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
36 | P a g e

game")

if(button1["text"]=="O" and button4["text"]=="O" and


button7["text"]=="O"):
button1.configure(background ="Powder Blue")
button4.configure(background ="Powder Blue")
button7.configure(background ="Powder Blue")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

if(button2["text"]=="O" and button5["text"]=="O" and


button8["text"]=="O"):
button2.configure(background ="Pink")
button5.configure(background ="Pink")
button8.configure(background ="Pink")

n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

if(button3["text"]=="O" and button6["text"]=="O" and


button9["text"]=="O"):
button3.configure(background ="Red")
button6.configure(background ="Red")
button9.configure(background ="Red")
n = float(PlayerO.get())
score = (n + 1)
PlayerO.set(score)
tkinter.messagebox.showinfo("Winner O", "You have just won a
game")

def reset():
button1['text']=" "
button2['text']=" "
37 | P a g e

button3['text']=" "
button4['text']=" "
button5['text']=" "
button6['text']=" "
button7['text']=" "
button8['text']=" "
button9['text']=" "

button1.configure(background ="gainsboro")
button2.configure(background ="gainsboro")
button3.configure(background ="gainsboro")
button4.configure(background ="gainsboro")
button5.configure(background ="gainsboro")
button6.configure(background ="gainsboro")
button7.configure(background ="gainsboro")
button8.configure(background ="gainsboro")
button9.configure(background ="gainsboro")

def NewGame():
reset()

PlayerX.set(0)
PlayerO.set(0)

lblPlayerX=Label(RightFrame1, font=('arial',40,'bold'), text="Player X


:",padx=2,pady=2, bg="Pink")
lblPlayerX.grid(row=0, column=0,sticky=W)
txtPlayerX=Entry(RightFrame1, font=('arial',40,'bold'), bd=2, fg = 'black',
textvariable= PlayerX, width=14,
justify=LEFT).grid(row=0,column=1)

lblPlayerO=Label(RightFrame1, font=('arial',40,'bold'), text="Player O


:",padx=2,pady=2, bg="Pink")
lblPlayerO.grid(row=1, column=0,sticky=W)
txtPlayerO=Entry(RightFrame1, font=('arial',40,'bold'), bd=2, fg =
'black', textvariable= PlayerO, width=14,
justify=LEFT).grid(row=1,column=1)

btnReset=Button(RightFrame2, text="Reset", font=('arial',40,'bold'),


height = 1, width=20, command = reset)
38 | P a g e

btnReset.grid(row=2, column=0, padx=6, pady=11)

btnNewGame=Button(RightFrame2, text="New Game",


font=('arial',40,'bold'), height=1, width=20, command = NewGame)
btnNewGame.grid(row=3, column=0, padx=6, pady=10)

button1 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button1))
button1.grid(row=1, column=0, sticky = S+N+E+W)

button2 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button2))
button2.grid(row=1, column=1, sticky = S+N+E+W)

button3 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button3))
button3.grid(row=1, column=2, sticky = S+N+E+W)

button4 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button4))
button4.grid(row=2, column=0, sticky = S+N+E+W)

button5 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button5))
button5.grid(row=2, column=1, sticky = S+N+E+W)

button6 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button6))
button6.grid(row=2, column=2, sticky = S+N+E+W)

button7 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button7))
button7.grid(row=3, column=0, sticky = S+N+E+W)

button8 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button8))
button8.grid(row=3, column=1, sticky = S+N+E+W)

button9 = Button(LeftFrame, text=" ", font=('Times 26 bold'), height=3,


width=8, bg='gainsboro', command=lambda:checker(button9))
button9.grid(row=3, column=2, sticky = S+N+E+W)

root.mainloop()
39 | P a g e

11. Limitations
1. GUI is not so attractive.

2. Only mouse interface is implemented, keyboard is not activated


in the game.

12. Future plan


1. Keyboard functions will be added.

2. We want to design more complex boards for the game in future.

13. Reference
Books
: 1. H.M.Deitel and P.J.Deital, Java How to program: Sixth
Edition Herbert Schildt, The Complete Reference: Fifth
edition

2. Youtube

3. Google Chrome

You might also like