You are on page 1of 12

AYAY KUMAR GARG ENGINEERING

COLLEGE

DEPARTMENT Of COMPUTER SCIENCE


ENGINEERING
MINI-PROJECT /SUMMER INTERNSHIP

SESSION: 2018-19

TOPIC: COLOUR GAME

LANGUAGE: PYTHON (TKINTER)

FACULTY INCHARGE: MS. PRIYANKA GABA

GROUP MEMBERS:(1+2)

1. Anshita kapoor (1802710021)

1
INDEX

1.Acknowledgment………………………………………3

2.Introduction……………………………………………..4
3.Concept …………………………………………………….5

4.Implementation…………………………………………6

5.Result ………………………………………………………..10

6.References…………………………………………………11

7.Declaration…………………………………………………12

2
Acknowledgement

We have taken efforts in this project. However, it would not


have been possible without the kind support and help of many
individuals and references. We would like to extend our sincere
thanks to all of them.

We are highly indebted to Ms. Priyanka Gaba ma’am for her


guidance and constant supervision as well as for providing
necessary information regarding the project & also for support
in completing the project.
We would like to express our gratitude towards ma’am for her
kind co-operation and encouragement which help us in
completion of this project.
We would like to express our special gratitude and thanks to
faculty for giving us such attention and time.
Our thanks and appreciations also go to our colleague in
developing the project and people who have willingly helped us
out with their abilities.

Introduction
3
What is Python?
Python is an interpreted, object-oriented, high-level programming
language with dynamic semantics. Its high-level built in data structures,
combined with dynamic typing and dynamic binding, make it very
attractive for Rapid Application Development, as well as for use as a
scripting or glue language to connect existing components together.
Python's simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance. Python supports
modules and packages, which encourages program modularity and code
reuse. The Python interpreter and the extensive standard library are
available in source or binary form without charge for all major platforms,
and can be freely distributed.

Python GUI – tkinter


Python offers multiple options for developing GUI (Graphical
User Interface). Out of all the GUI methods, tkinter is most
commonly used method. It is a standard Python interface to the
Tk GUI toolkit shipped with Python. Python with tkinter outputs
the fastest and easiest way to create the GUI applications.
Creating a GUI using tkinter is an easy task.
To create a tkinter:
1. Importing the module – tkinter
2. Create the main window (container)
3. Add any number of widgets to the main window
4. Apply the event Trigger on the widgets.

Concept

4
In this game we have to enter color of the word that appears on the
screen and hence the score increases by one, the total time to play this
game is 30 seconds. Colors used in this game are Red, Blue, Green,
Pink, Black, Yellow, Orange, White, Purple and Brown. Interface will
display name of different colors in different colors. We have to
identify the color and choose the correct color name to win the game.

Implementation (code)
import tkinter

5
import random

colours = ['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score = 0
timeleft = 30

def startGame(event):

if timeleft == 30:

countdown()

# function to choose the next colour.


nextColour()

def nextColour():

global score
global timeleft

if timeleft > 0:

# make the text entry box active.


e.focus_set()

# if the colour typed is equal to the colour of the text


if e.get().lower() == colours[1].lower():

6
score += 1

# clear the text entry box.


e.delete(0, tkinter.END)

random.shuffle(colours)

# change the colour to type, by changing the text _and_ the colour to a
random colour value
label.config(fg = str(colours[1]), text = str(colours[0]))

# update the score.


scoreLabel.config(text = "Score: " + str(score))

def countdown():

global timeleft

if timeleft > 0:

timeleft -= 1

timeLabel.config(text = "Time left: "


+ str(timeleft))

# run the function again after 1 second.


timeLabel.after(1000, countdown)
7
# Driver Code

# create a GUI window


root = tkinter.Tk()

root.title("COLORGAME")

root.geometry("400x200")

# add an instructions label


instructions = tkinter.Label(root, text = "Type in the colour"
" of the words, and not the word text!",
font = ('Helvetica', 12))
instructions.pack()
scoreLabel = tkinter.Label(root, text = "Press enter to start",
font = ('Helvetica', 12))
scoreLabel.pack()

# add a time left label


timeLabel = tkinter.Label(root, text = "Time left: " +
str(timeleft), font = ('Helvetica', 12))

timeLabel.pack()

# add a label for displaying the colours


label = tkinter.Label(root, font = ('Helvetica', 60))
label.pack()
8
e = tkinter.Entry(root)
root.bind('<Return>', startGame)
e.pack()
e.focus_set()
root.mainloop()

RESULTS

9
10
References

 youtube
 Wikipedia.com
 geeksforgeeks
 w3schools
 Google

11
Declaration

I hereby declare that the above project is completed by me and my


team mate and is best to my Knowledge.

12

You might also like