
In the above code, I have imported tkinter for the GUI itself and random to randomly select the color from the list. If(displayed_word_color = color_entry.get().lower()):ĭisplay_nfig(text = random.choice(colors), fg = displayed_word_color) Time_nfig(text = "Game Ends in : " + str(timer) + "s") Game_nfig(text = "Your Score : " + str(score)) Global timer, score, displayed_word_color #This fuction will be called when start button is clickedĭisplayed_word_color = random.choice(colors).lower()ĭisplay_nfig(text=random.choice(colors), fg=displayed_word_color)
#Color war tkinter code#
Here is the complete code for Color Game in Tkinter. Then I defined some functions to handle the button clicks and track the score, display random words with different colors, to start the count down, etc. The code above will create an interface like this. The start button is used to start the game and the reset button will reset the game so that players can start the game from the beginning. Two buttons are placed at the bottom of the window namely start and reset. Then I have placed some labels which display the current score, words with different colors and count down timer.
#Color war tkinter how to#
The above code will create a window inside which I have placed some description of the game and how to play the game.

Reset_button = Button(btn_frame, text = "Reset", width = 20, fg = "black", bg = "light blue", bd = 0,padx = 20, pady = 10, command = resetGame) Start_button = Button(btn_frame, text = "Start", width = 20, fg = "black", bg = "pink", bd = 0,padx = 20, pady = 10, command = startGame) Time_left = Label(my_window, text = "Game Ends in : -", font = (font.Font(size=14)), fg = "orange")Ĭolor_entry = Entry(my_window, width = 30)ītn_frame = Frame(my_window, width= 80, height = 40, bg= 'red') Game_score = Label(my_window, text = "Your Score : " + str(score), font = (font.Font(size=16)), fg = "green")ĭisplay_words = Label(my_window, font = (font.Font(size=28)), pady = 10) Game_description = Label(my_window, text = game_desp, font = app_font, fg= "grey")

\n And Keep in mind not to enter the word text itself"

Game_desp = "Game Description: Enter the color of the words displayed below. from tkinter import *Ĭolors = Īpp_font = font.Font(family='Helvetica', size = 12) To implement the user interface I wrote the following code. Implementing Color Game using Tkinter Python
