100% found this document useful (2 votes)
3K views

Python Mini Project

The document discusses developing a color guessing game using the Tkinter GUI module in Python, where the player has 30 seconds to identify the color of words displayed on screen in different colors by entering the correct color name, with their score increasing for each correct guess. It outlines collecting color names in a list, displaying words in random colors, checking the user's input against the correct color, and decrementing a timer. The purpose is to demonstrate how to build a simple game interface using Tkinter for the GUI.

Uploaded by

SHREE MEHER
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views

Python Mini Project

The document discusses developing a color guessing game using the Tkinter GUI module in Python, where the player has 30 seconds to identify the color of words displayed on screen in different colors by entering the correct color name, with their score increasing for each correct guess. It outlines collecting color names in a list, displaying words in random colors, checking the user's input against the correct color, and decrementing a timer. The purpose is to demonstrate how to build a simple game interface using Tkinter for the GUI.

Uploaded by

SHREE MEHER
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

ABSTRACT:

Tkinter is widely used for developing GUI applications. Along with


applications, we can also use Tkinter GUI to develop games.

Let’s try to make a game using Tkinter. In this game player has 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. Player has to identify the color and enter the correct color
name to win the game.
TABLE OF CONTENTS:
1. Introduction

2. Literature Review

3. Methodology

4. Results & Discussion

5. Summary & Conclusion

6. References:
1. INTRODUCTION

(i) AIM: To use “Tkinter GUI” to develop games


.
(ii) OBJECTIVE: Let's try to make a game using Tkinter. In
this game player has 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.

(iii) SCOPE: Help with populating your game world.

 Tutorial: Building Quick-start - helps you build your first rocks


and crates using Tkinter.
 Tutorial: Understanding Color Tags - explains how you color your
game's text.
 Introduction: The Tutorial World - this introduces the full (if small)
solo-adventure game that comes with the Tkinter GUI. It is useful
both as an example of building and of coding.
 Tutorial: Building a Giant Mech - this starts as a building tutorial
and transitions into writing code.
2. LITREATURE REVIEW
(i) Research Survey : Papers/Website of Past Research:
In formal, peer-reviewed meta-analyses, people will pre-specify a set of
keywords, search on those keywords in curated databases, read the
abstract of every result and decide whether to include it based on that.
Don’t do that. It’s incredibly time-consuming.3
I generally take a less systematic approach. I’ll look through the first few
pages of Google Scholar for a bunch of relevant searches, taking note of
any papers that look relevant, until I think I’m hitting diminishing
returns. Then as I read those papers I’ll take note of any citations that
seem like they might also be worth including. This seems to find most or
all of the available papers. It’s somewhat more prone to bias, since it’s
less well-defined than the keyword-search approach, but I don’t think
that’s a huge issue if you’re diligent about it.
However, it does make you more likely to miss an important paper on
the first time through. So if you take this approach, it’s important that
you use spreadsheets or programs to make it easy to add more papers
after your initial search.
LINKS :
1. https://www.geeksforgeeks.org/color-game-python/
2. https://dzone.com/articles/python-gui-examples-tkinter-tutorial-like-geeks
3. METHODOLGY

(i) Problem Statement :

1. Simple Python Programs :


This section deals with Simple Python Programs. The Python programs in this
section performs arithmetic operations like Addition, Multiplication and Division
on the given set of input numbers. This section also covers python programs on
reversing the given number and checks whether the given number is positive or
negative number. The other programs in this section checks whether a given
number is palindrome or not, prints identity matrix and inverted star pattern,
print prime numbers in a given range using sieve of eratosthenes method. It also
talks about python programs on exchanging two number values without using
any temporary variables, counting the number of integers in a given number,
entering the student marks in 5 subjects and displaying the grades.

2. Python Programming Examples on Mathematical Functions :


The following section contains programs on different types of mathematical
functions. These include programs to checks whether the given number is strong
number, perfect number, prime number or armstrong number. It also checks
whether a given year is leap year or not. The Python programming examples
also covers programs on performing simple interest with given values, printing
the largest even and odd number in the given list. Python programs on number
conversions like converting celcius temperature to farenheit temperature, gray
code to binary and binary code to gray. This section also covers python
programs on finding the lcm and gcd of two numbers and also checks whether
the two given numbers are amicable numbers or not. The other programs in this
section prints all prime numbers in a given range, print the pascal triangle,
programs on trigonometric functions such as sin(x) and cos(x).

3. Python Programming Examples on Lists :


This section contains Python programs examples on Lists. List is a collection of
data or information which is ordered and changeable. Lists are written with
square brackets. List is used to store the multiple data at a same time. Each
element which is inside the list is called an item. The Python programs in this
section finds the largest and second largest number in the given list, it also finds
the second largest number using bubble sort algorithm. The Python
programming examples also contains programs on sorting the given list
according to their lengths, merging two lists and sort it, finds the intersection of
two lists. The other python programs in this section performs swapping values
and removing duplicate values from the list, program to solve maximum
subarray problem using kadane’s and divide and conquer algorithms. It also
talks about python programs on finding the number which is having perfect
square in a given range of numbers.

(ii)Analysis & Design : Tkinter is widely used for developing GUI


applications. Along with applications, we can also use Tkinter GUI to develop
games.

Let’s try to make a game using Tkinter. In this game player has 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. Player has to identify the
color and enter the correct color name to win the game.
4. Results & Discussion

(i) Source Code(Soft Copy) :

# import the modules


import tkinter
import random

# list of possible colour.


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

# the game time left, initially 30 seconds.


timeleft = 60

# function that will start the game.


def startGame(event):

if timeleft == 60:

# start the countdown timer.


countdown()

# run the function to


# choose the next colour.
nextColour()

# Function to choose and


# display the next colour.
def nextColour():

# use the globally declared 'score'


# and 'play' variables above.
global score
global timeleft

# if a game is currently in play


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():

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))

# Countdown timer function


def countdown():

global timeleft

# if a game is in play
if timeleft > 0:

# decrement the timer.


timeleft -= 1

# update the time left label


timeLabel.config(text = "Time left: "
+ str(timeleft))

# run the function again after 1 second.


timeLabel.after(1000, countdown)

# Driver Code

# create a GUI window


root = tkinter.Tk()

# set the title


root.title("COLORGAME")

# set the size


root.geometry("375x200")

# 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()

# add a score label


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()

# add a text entry box for


# typing in colours
e = tkinter.Entry(root)

# run the 'startGame' function


# when the enter key is pressed
root.bind('<Return>', startGame)
e.pack()

# set focus on the entry box


e.focus_set()

# start the GUI


root.mainloop()

(ii) Result (Output screen) :


5. Summary & Conclusion:

(i) Summary: 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.

(ii) Conclusion: Tkinter is excellent for small, quick GUI


applications, and since it runs on more platforms than any other Python
GUI toolkit, it is a good choice where portability is the prime concern.
Obviously we haven’t been able to give Tkinter the depth of discussion it
warrants, but it’s fair to say that almost anything that can be done using
the C language and Tk can be done using Python and Tkinter. One
example is the Python megawidgets (PMW) package mentioned
previously; this is a pure Python package that creates an excellent
widget set by building on the core Tkinter widgets.

6. References
(i) Technical Paper Details : Tk/Tcl has long been an integral part of
Python. It provides a robust and platform independent windowing toolkit, that is
available to Python programmers using the tkinter package, and its extension,
the tkinter.tix and the tkinter.ttk modules.

The tkinter package is a thin object-oriented layer on top of Tcl/Tk. To


use tkinter, you don’t need to write Tcl code, but you will need to consult the Tk
documentation, and occasionally the Tcl documentation. tkinter is a set of
wrappers that implement the Tk widgets as Python classes. In addition, the
internal module _tkinterprovides a threadsafe mechanism which allows Python
and Tcl to interact.

tkinter’s chief virtues are that it is fast, and that it usually comes bundled with
Python. Although its standard documentation is weak, good material is available,
which includes: references, tutorials, a book and others. tkinter is also famous
for having an outdated look and feel, which has been vastly improved in Tk 8.5.
Nevertheless, there are many other GUI libraries that you could be interested in.
For more information about alternatives, see the Other Graphical User Interface
Packages section.

(ii) Web reference : To learn more about any of the Tkinter topics
discussed here, you may like to refer to the following sources:

i. The standard Python documentation is optionally installed with Python on


Windows and is also available online at http://www.python.org/doc.
ii. PythonWare and Fredrik Lundh provide excellent Tkinter resources,
including tutorials available at http://www.pythonware.com.
iii. Tcl and Tk are developed and supported by the Scriptics Corporation,
which can be found at http://www.scriptics.com. Tcl and Tk documentation
is available from http://www.scriptics.com/resource/doc/.
iv. Python megawidgets are available via http://pmw.sourceforge.net/.

(iii) Reference & Text books:


i. O’Reilly has an excellent book on the subject, Tcl/Tk in a Nutshell by
Paul Raines and Jeff Trantor
ii. O’Reilly’s Tkinter Programming by Fredrik Lundh.

You might also like