|
| 1 | + |
| 2 | +from tkinter import * |
| 3 | +from tkinter import messagebox |
| 4 | +import tkinter.messagebox as mbox |
| 5 | +import tkinter as tk |
| 6 | + |
| 7 | + |
| 8 | +# created a main window |
| 9 | +root = Tk() |
| 10 | +root.title("Word Search Game") |
| 11 | +root.geometry('1100x750') |
| 12 | + |
| 13 | + |
| 14 | +# ------------------------------------- frame0 ------------------------------------- |
| 15 | +def des_f0(): |
| 16 | + f0.destroy() |
| 17 | + |
| 18 | +# function defined to show rules |
| 19 | +def show_rules(): |
| 20 | + mbox.showinfo("RULES", "1.) Player will be given word board with alphabets in it.\n\n2.) There will 15 words will be displayed on screen one by one and player need to YES or NO for that word is present in word board or not respectively.\n\n3.) The points each word will be shown at the top right corner.\n\n4.) At last, final score will be shown along with count of correct and wrong answer, and also user can see the words that are present in it at the end.") |
| 21 | + |
| 22 | +# created first main frame |
| 23 | +f0 = Frame(root, height=750, width=1100) |
| 24 | +f0.propagate(0) |
| 25 | +f0.pack(side='top') |
| 26 | + |
| 27 | +# function for adding image in frame 1 |
| 28 | +c = Canvas(f0, width=1100, height=750) |
| 29 | +c.pack() |
| 30 | +p = PhotoImage(file='Images/front.gif') |
| 31 | +c.create_image(130, 50, image=p, anchor=NW) |
| 32 | + |
| 33 | +# created start button |
| 34 | +startb = Button(f0, text="START",command=des_f0,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised") |
| 35 | +startb.place(x = 120 , y =600 ) |
| 36 | + |
| 37 | +# created start button |
| 38 | +rulesb = Button(f0, text="RULES",command=show_rules,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised") |
| 39 | +rulesb.place(x = 480 , y =600 ) |
| 40 | + |
| 41 | +# ------------------------- frame1 - level1 -------------------------------------- |
| 42 | +word_ques = ["MOUSE","JAGUAR","LION", "FERRET","GIBREL","FISH","PEACOCK","CHINCHILLA","GUINEA","PIGEON","CHICKEN", "SNAKE","FLAMINGO","TURTLE","LIZARD"] |
| 43 | +word_ans = ["YES","NO","NO", "YES","YES","YES","NO","YES","YES","NO","YES", "YES","NO","YES","YES"] |
| 44 | + |
| 45 | +ind = -1 |
| 46 | +cr = 0 |
| 47 | +wr = 0 |
| 48 | +cnt = 15 |
| 49 | +def initial(): |
| 50 | + global ind |
| 51 | + |
| 52 | + ind = ind + 1 |
| 53 | + word.configure(text=word_ques[ind]) |
| 54 | + |
| 55 | +def see_ans(): |
| 56 | + f2.destroy() |
| 57 | + |
| 58 | + f3 = Frame(root, width=1100, height=750) |
| 59 | + f3.propagate(0) |
| 60 | + f3.pack(side='top') |
| 61 | + |
| 62 | + c3 = Canvas(f3, width=1100, height=750, bg="white") # blue |
| 63 | + c3.pack() |
| 64 | + p3 = PhotoImage(file="Images/score1.gif") |
| 65 | + c3.create_image(150, 10, image=p3, anchor="nw") |
| 66 | + w3 = Canvas(root) |
| 67 | + w3.p3 = p3 |
| 68 | + |
| 69 | + |
| 70 | +def next_switch(): |
| 71 | + global ind, cnt |
| 72 | + cnt = cnt - 1 |
| 73 | + if (cnt >= 0): |
| 74 | + lives_cnt1 = tk.Label(text=" ", font=("Arial", 30), fg="brown") |
| 75 | + lives_cnt1.place(x=940, y=20) |
| 76 | + lives_cnt = tk.Label(text=cnt, font=("Arial", 30), fg="brown") # same way bg |
| 77 | + lives_cnt.place(x=940, y=20) |
| 78 | + if (cnt == -1): |
| 79 | + mbox.showinfo("GAME OVER", "GAME OVER !") |
| 80 | + f1.destroy() |
| 81 | + |
| 82 | + f2 = Frame(root, width=1100, height=750) |
| 83 | + f2.propagate(0) |
| 84 | + f2.pack(side='top') |
| 85 | + |
| 86 | + c2 = Canvas(f2, width=1100, height=750, bg="white") # blue |
| 87 | + c2.pack() |
| 88 | + p2 = PhotoImage(file="Images/score1.gif") |
| 89 | + c2.create_image(350, 10, image=p2, anchor="nw") |
| 90 | + w2 = Canvas(root) |
| 91 | + w2.p2 = p2 |
| 92 | + |
| 93 | + score1 = Label(f2, text=str(cr * 10) + "/150", font=("Arial", 100), fg="green", bg="white") |
| 94 | + score1.place(x=350, y=250) |
| 95 | + |
| 96 | + see1 = Label(f2, text="SEE HOW WELL YOU CAN SEARCH WORDS", font=("Arial", 30), fg="brown", bg="light yellow") |
| 97 | + see1.place(x=150, y=500) |
| 98 | + see2 = Label(f2, text="Correct Answer :" + str(cr) + "/15", font=("Arial", 30), fg="orange", |
| 99 | + bg="white") |
| 100 | + see2.place(x=350, y=580) |
| 101 | + see3 = Label(f2, text="Wrong Answer :" + str(wr) + "/15", font=("Arial", 30), fg="blue", bg="white") |
| 102 | + see3.place(x=350, y=650) |
| 103 | + # # keyboard button created for opening keyboard |
| 104 | + # seeansb = Button(f2, text="SEE ANS", command=see_ans, font=("Arial", 20), bg="light green", fg="blue",borderwidth=3, relief="raised") |
| 105 | + # seeansb.place(x=860, y=650) |
| 106 | + |
| 107 | + m1 = mbox.askokcancel("Final Answer", "Do You want to see Final Answer") |
| 108 | + if(m1): |
| 109 | + f2.destroy() |
| 110 | + |
| 111 | + f3 = Frame(root, width=1100, height=750) |
| 112 | + f3.propagate(0) |
| 113 | + f3.pack(side='top') |
| 114 | + |
| 115 | + c3 = Canvas(f3, width=1100, height=750, bg="white") # blue |
| 116 | + c3.pack() |
| 117 | + p3 = PhotoImage(file="Images/final_ans.gif") |
| 118 | + c3.create_image(150, 10, image=p3, anchor="nw") |
| 119 | + w3 = Canvas(root) |
| 120 | + w3.p3 = p3 |
| 121 | + |
| 122 | + |
| 123 | + ind = ind + 1 |
| 124 | + if(ind<=14): |
| 125 | + word.configure(text=word_ques[ind]) |
| 126 | + |
| 127 | +def answer_check(): |
| 128 | + global cr, wr |
| 129 | + selected_ans = word1_var.get() |
| 130 | + if(ind<=14): |
| 131 | + if(selected_ans == word_ans[ind]): |
| 132 | + mbox.showinfo('Success', 'Your answer is correct') |
| 133 | + cr = cr + 1 |
| 134 | + next_switch() |
| 135 | + else: |
| 136 | + mbox.showerror('Error','Your answer is wrong') |
| 137 | + wr = wr + 1 |
| 138 | + next_switch() |
| 139 | + else: |
| 140 | + next_switch() |
| 141 | + |
| 142 | + |
| 143 | +# created frame 1 |
| 144 | +f1 = Frame(root, height=750, width=1100) |
| 145 | +f1.propagate(0) |
| 146 | +f1.pack(side='top') |
| 147 | + |
| 148 | +# function for adding image in frame 1 |
| 149 | +c1 = Canvas(f1, width=1100, height=750) |
| 150 | +c1.pack() |
| 151 | +p1 = PhotoImage(file='Images/final_ques.gif') |
| 152 | +c1.create_image(20, 10, image=p1, anchor=NW) |
| 153 | + |
| 154 | +lives = tk.Label(f1,text = "Lives : ", font=("Arial", 30), fg="brown") # same way bg |
| 155 | +lives.place(x = 800, y = 20) |
| 156 | + |
| 157 | +lives_cnt = tk.Label(f1,text = 15, font=("Arial", 30), fg="brown") # same way bg |
| 158 | +lives_cnt.place(x = 940, y = 20) |
| 159 | + |
| 160 | +# label for showing points on tp right corner |
| 161 | +points1 = Label(f1, text="Points : " + str(10), font=("Arial", 35), fg="magenta") |
| 162 | +points1.place(x = 800, y = 80) |
| 163 | + |
| 164 | +# for starting top label |
| 165 | +word = Label(f1, font=("Arial", 30), fg="brown") |
| 166 | +word.place(x=800, y=250) |
| 167 | + |
| 168 | +# for starting top label |
| 169 | +select = Label(f1, text='Select Ans : ', font=("Arial", 30), fg="green") |
| 170 | +select.place(x=750, y=320) |
| 171 | + |
| 172 | +word1_var = tk.StringVar() |
| 173 | +word1_choices = ["YES", "NO"] |
| 174 | +word1_menu = OptionMenu(f1, word1_var, *word1_choices) |
| 175 | +word1_menu.config(font=("Arial", 20), bg="light green", fg="blue", borderwidth=3) |
| 176 | +word1_menu["menu"].config(font=("Arial", 15), bg="light yellow", fg="blue") |
| 177 | +word1_menu.place(x=980, y=320) |
| 178 | +word1_var.set("NO") |
| 179 | + |
| 180 | +# keyboard button created for opening keyboard |
| 181 | +checkb = Button(f1, text="CHECK",command=answer_check,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised") |
| 182 | +checkb.place(x =840 , y =480 ) |
| 183 | + |
| 184 | +initial() |
| 185 | +# ------------------------------------------------------------------------------------- |
| 186 | + |
| 187 | + |
| 188 | +# function for exiting |
| 189 | +def exit_win(): |
| 190 | + if messagebox.askokcancel("Exit", "Do you want to exit?"): |
| 191 | + root.destroy() |
| 192 | + |
| 193 | +# created exit button |
| 194 | +exitb = Button(root, text="EXIT",command=exit_win,font=("Arial", 20), bg = "red", fg = "blue", borderwidth=3, relief="raised") |
| 195 | +exitb.place(x =860 , y =600 ) |
| 196 | + |
| 197 | + |
| 198 | +root.protocol("WM_DELETE_WINDOW", exit_win) |
| 199 | +root.mainloop() |
0 commit comments