Coders Packet

Color_Game using Tkinter (Python)

By Kunjesh Mahajan

I had created a color game in which you will be given the name of any random color highlighted with different color and you have to type the name of the highlighted.

Programming Language used Python.

I have used some of the following modules, functions, and widgets which are different from what we use regularly in Python language. The project is based on the Tkinter module.

1. focus_set() -The Function basically uses in GUI windows . In this all keyboard events sent to the application will be routed to this widget. It’s like activating the text box where you type the text. 

if timeleft > 0: 

2. .after()-This method is used to call the given function after a given delay in ms. The syntax is given below.

if timeleft > 0:  
        timeleft -= 1
        timeLabel.config(text = "Time left: "+ str(timeleft)) 
        timeLabel.after(1000, countdown) 

3. .get() - This function is used to take values and store them. This is a normal “get” function.

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

4.random.shuffle() - This is used to shuffle any list so that we can use any random number. By using this you can’t predict what number will come.

if e.get().lower() == colours[1].lower(): 
            score += 1
        e.delete(0, tkinter.END) 

5. bind(sequence =none, function =none, add =none) - This adds an event binding to this site. Here we can add any command key and function, by pressing that key the given function starts running. 

def reset():
    d.set(' ')
    timeLabel.config(text = "Time left: "+"10") 
    scoreLabel.config(text = "Score: " + "0")
    root.bind('', startGame)


Download Complete Code


No comments yet