Skip to content

Commit c037d51

Browse files
committed
renamed folder
1 parent 1edf01f commit c037d51

File tree

12 files changed

+393
-0
lines changed

12 files changed

+393
-0
lines changed
53.3 KB
Loading
Loading
68 KB
Loading
59.6 KB
Loading
69.7 KB
Loading
61.3 KB
Loading
60.3 KB
Loading
82.7 KB
Loading
77.2 KB
Loading

Diff for: PyGamesScripts/Jumbled Words Guessing Game/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Jumbled Words Guessing Game
2+
Jumbled words guessing game is a game developed in python programming Language using random module and tkinter module.
3+
4+
## About the game
5+
* It is a single player word guessing game
6+
* The user can keep guessing words as long as he wants to play
7+
8+
## How to play?
9+
* The user has to press the start button to start playing the game
10+
* The user has to choose a category he wishes from the given list
11+
* Then the jumbled word will be displayed
12+
* The user has to type the word he thinks is the right word in the box provided and press the submit button
13+
* If the user found the right word the game will automatically move to the next word after the message
14+
* A pop up box will show if the answer is right or wrong
15+
* If the user wants to see the answer he can press the answer button which will provide the ans
16+
* If the user wants to go to the next word without trying the present word or after seeing the answer for the given word he can press the next word button
17+
* If the user wants to exit the game he can click the exit button
18+
19+
## Setup instructions
20+
1. Install Python 3.x (recommended) from https://www.python.org/downloads/
21+
2. Download this repository as zip and extract.
22+
3. Run the code and start playing.
23+
4. Have fun!!
24+
25+
## Real time use and purpose
26+
* It is used to play jumbled words game which sharpens your mind and is also a source of distraction
27+
28+
## Output
29+
![GitHub Logo](Images/guessing.png)
30+
31+
32+
## Author
33+
K.Harshitha
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
import tkinter
2+
from tkinter.constants import END
3+
from tkinter.font import names
4+
import random
5+
from tkinter import Label, messagebox
6+
from typing import Text
7+
#import tkMessageBox
8+
9+
#list of categories and words in each list
10+
fruits =["apple","pineapple","orange","mango","banana","cherry"]
11+
countries =["india", "australia","england","germany","austria","indonesia","japan","singapore"]
12+
superheroes = ["batman","batwoman","catwoman","hawkeye","supergirl","thor","flash"]
13+
vegetables = ["tomato","potato","brinjal","onion","mushroom"]
14+
sco = 0
15+
score_txt ="Score:- "+str(sco)
16+
17+
#This function is called when the user presses the exit button
18+
def destroy_fn():
19+
#this will show a pop up window
20+
messagebox.showinfo("EXIT MESSAGE","Thank you for playing the game")
21+
#this is used to destroy window and exit game
22+
gamewindow.destroy()
23+
24+
#This function is called when the user presses the next word button
25+
def next_word(cat):
26+
global word
27+
jword =""
28+
cat = cat.lower()
29+
#print("catloer is ",cat)
30+
#word = cat[random.randrange(0,len(cat))]
31+
#jumble = random.sample(word,len(word))
32+
#for i in jumble:
33+
# jword += i
34+
#print("inside next word")
35+
#choosing a random word from the chossen category
36+
if(cat == "fruits"):
37+
word = random.choice(fruits)
38+
elif(cat =="countries"):
39+
word = random.choice(countries)
40+
elif(cat == "superheroes"):
41+
word = random.choice(superheroes)
42+
elif(cat == "vegetables"):
43+
word = random.choice(vegetables)
44+
#print("word is ",word)
45+
#jumble the letters of the word
46+
jumble = random.sample(word,len(word))
47+
#converting the lsit to string
48+
for i in jumble:
49+
jword += i
50+
51+
#print("jword is ",jword)
52+
#displaying the word
53+
word_label.configure(text = jword)
54+
#deleting the existing text in the text box
55+
get_input.delete(0, END)
56+
#print("end of next word")
57+
#deleting the ans shown
58+
ans_space.configure(text ="")
59+
60+
#this function is called when the user presses the answer key
61+
def showans():
62+
global word
63+
#showing the answer
64+
ans_space.configure(text = word)
65+
66+
#This function is called when the user presses the submit button
67+
def check_word(cat):
68+
#guess = get_input.get().lower()
69+
global sco,word
70+
#print("word is ", word)
71+
#print("inside check eord")
72+
#user_input = get_input.get()
73+
#storing the user input
74+
guess = get_input.get().lower()
75+
#print(user_word)
76+
#checking if the guessed word is right
77+
if(guess == word):
78+
#print("correct")
79+
#shoeing a po up mesage if guess is right
80+
messagebox.showinfo("CORRECT ANS", "CONGRATULATIONS!!!!!! you found the right word")
81+
#displaying the next word
82+
next_word(cat)
83+
# jword =""
84+
# cat = cat.lower()
85+
# #print("catloer is ",cat)
86+
# #word = cat[random.randrange(0,len(cat))]
87+
# #jumble = random.sample(word,len(word))
88+
# #for i in jumble:
89+
# # jword += i
90+
# if(cat == "fruits"):
91+
# word = random.choice(fruits)
92+
# elif(cat =="countries"):
93+
# word = random.choice(countries)
94+
# elif(cat == "superheroes"):
95+
# word = random.choice(superheroes)
96+
# elif(cat == "vegetables"):
97+
# word = random.choice(vegetables)
98+
# print("word is ",word)
99+
# jumble = random.sample(word,len(word))
100+
# for i in jumble:
101+
# jword += i
102+
103+
# print("jword is ",jword)
104+
# word_label.configure(text = jword)
105+
# get_input.delete(0, END)
106+
#deleting the ans shown
107+
ans_space.configure(text ="")
108+
return
109+
else:
110+
#pop up box for wrong message
111+
messagebox.showinfo("WRONG ANS", "Please try again")
112+
#print("Wrong")
113+
#deleting thw prv user input
114+
get_input.delete(0, END)
115+
116+
117+
118+
119+
#this fn is used to create the game window
120+
def game(cat,jword):
121+
#print("hello")
122+
global word
123+
#print("word is ",word)
124+
#print("jumbled word is",jword)
125+
#destroying the intro window
126+
root.destroy()
127+
global gamewindow
128+
#creating the game window
129+
gamewindow = tkinter.Tk()
130+
gamewindow.geometry("600x600+600+200")
131+
gamewindow.title(cat)
132+
gamewindow.configure(bg="light blue")
133+
global score
134+
135+
global word_label
136+
#diplaying the word
137+
word_label = tkinter.Label(
138+
gamewindow,
139+
text=jword,
140+
pady=10,
141+
bg="light blue",
142+
fg="#000000",
143+
font="Titillium 50 bold"
144+
)
145+
word_label.pack()
146+
global get_input
147+
answer = tkinter.StringVar()
148+
# displaying the input box
149+
get_input = tkinter.Entry(
150+
font="none 26 bold",
151+
borderwidth=10,
152+
justify='center',
153+
textvariable= answer
154+
)
155+
get_input.pack()
156+
#user_word = get_input.get().upper()
157+
#guess = get_input.get().lower()
158+
#print(user_word)
159+
#displaying submit buutton whixh calls check word
160+
submit = tkinter.Button(
161+
gamewindow,
162+
text="SUBMIT",
163+
width=18,
164+
borderwidth=8,
165+
font=("", 18),
166+
fg="#000000",
167+
bg="light green",
168+
#cursor="hand2",
169+
command=lambda:check_word(cat)
170+
)
171+
submit.pack(pady=(10,20))
172+
173+
#displaying answer button which calls showans fn
174+
ans = tkinter.Button(
175+
gamewindow,
176+
text="ANSWER",
177+
width=18,
178+
borderwidth=8,
179+
font=("", 18),
180+
fg="#000000",
181+
bg="light green",
182+
#cursor="hand2",
183+
command=lambda: showans(),
184+
)
185+
ans.pack(pady=(10,20))
186+
187+
#displaying next word button which calls nextword fn
188+
nextWord = tkinter.Button(
189+
gamewindow,
190+
text="NEXT WORD",
191+
width=18,
192+
borderwidth=8,
193+
font=("", 18),
194+
fg="#000000",
195+
bg="light green",
196+
#cursor="hand2",-
197+
command=lambda:next_word(cat)
198+
)
199+
nextWord.pack(pady=(10,20))
200+
201+
#displaing exxit button which calls destroy fn
202+
exit_btn = tkinter.Button(
203+
gamewindow,
204+
text="EXIT",
205+
width=18,
206+
borderwidth=8,
207+
font=("", 18),
208+
fg="#000000",
209+
bg="light green",
210+
#cursor="hand2",
211+
command=lambda:destroy_fn()
212+
)
213+
exit_btn.pack(pady=(10,20))
214+
215+
216+
global ans_space
217+
#shows the ans when needed initaaly it doesn not display anything
218+
ans_space = tkinter.Label(
219+
gamewindow,
220+
text="",
221+
pady=10,
222+
bg="light blue",
223+
fg="#000000",
224+
font="Courier 15 bold"
225+
)
226+
ans_space.pack()
227+
228+
gamewindow.mainloop()
229+
230+
#this fn is used to find a random word from the choosen category and jumble it and then call the game fn
231+
def start_game(args):
232+
global word
233+
jword =""
234+
#print(args)
235+
if(args == 1):
236+
word = random.choice(fruits)
237+
jumble = random.sample(word,len(word))
238+
for i in jumble:
239+
jword += i
240+
# print(word,jword)
241+
game("FRUITS",jword)
242+
elif(args == 2):
243+
word = random.choice(countries)
244+
jumble = random.sample(word,len(word))
245+
for i in jumble:
246+
jword += i
247+
# print(word,jumble)
248+
game("COUNTRIES",jword)
249+
elif(args == 3):
250+
word = random.choice(superheroes)
251+
jumble = random.sample(word,len(word))
252+
for i in jumble:
253+
jword += i
254+
# print(word,jumble)
255+
game("SUPERHEROES",jword)
256+
elif(args == 4):
257+
word = random.choice(vegetables)
258+
jumble = random.sample(word,len(word))
259+
for i in jumble:
260+
jword += i
261+
#print(word,jumble)
262+
game("VEGETABLES",jword)
263+
264+
265+
#this fn is to show the options to the user
266+
def disp_option():
267+
#print("hi")
268+
#destroying all the elements which were previously displayed
269+
start_btn.destroy()
270+
label.destroy()
271+
#Displaying fruits button
272+
sel_btn1 = tkinter.Button(
273+
root,
274+
text="Fruits",
275+
width=30,
276+
borderwidth=10,
277+
font=("", 18),
278+
fg="#000000",
279+
bg="#99ffd6",
280+
cursor="hand2",
281+
command=lambda: start_game(1),
282+
)
283+
#Displaying countries button
284+
sel_btn2 = tkinter.Button(
285+
root,
286+
text="Countries",
287+
width=30,
288+
borderwidth=10,
289+
font=("", 18),
290+
fg="#000000",
291+
bg="#99ffd6",
292+
cursor="hand2",
293+
command=lambda: start_game(2),
294+
)
295+
#Displaying superheores button
296+
sel_btn3 = tkinter.Button(
297+
root,
298+
text="Superheroes",
299+
width=30,
300+
borderwidth=10,
301+
font=("", 18),
302+
fg="#000000",
303+
bg="#99ffd6",
304+
cursor="hand2",
305+
command=lambda: start_game(3),
306+
)
307+
#Displaying vegetables button
308+
sel_btn4 = tkinter.Button(
309+
root,
310+
text="Vegetables",
311+
width=30,
312+
borderwidth=10,
313+
font=("", 18),
314+
fg="#000000",
315+
bg="#99ffd6",
316+
cursor="hand2",
317+
command=lambda: start_game(4),
318+
)
319+
#alliging the buttons
320+
sel_btn1.grid(row=0, column=100, pady=(10, 0), padx=450 )
321+
sel_btn2.grid(row=2, column=100, pady=(10, 0), padx=450 )
322+
sel_btn3.grid(row=4, column=100, pady=(10, 0), padx=450 )
323+
sel_btn4.grid(row=6, column=100, pady=(10, 0), padx=450 )
324+
325+
326+
327+
#creating the start window
328+
root = tkinter.Tk()
329+
root.geometry("600x600+600+200")
330+
root.title("JUMBLED WORDS GUESSING GAME")
331+
root.configure(bg="#856ff8")
332+
label = tkinter.Label(root,font='times 35',text= "WELCOME TO JUMBLED WORDS GUESSING GAME ",bg= "#856ff8")#.place(x=30,y=60)
333+
label.pack(pady =(150,0))#pady=30,ipady=150,ipadx=10)
334+
335+
#name = tkinter.StringVar()
336+
#e1 = tkinter.Entry(root,textvariable=name)
337+
#e1.pack(ipady=0,ipadx= 0 )
338+
#print(name)
339+
#displying the start button which when clicked will call the disp_option fn
340+
start_btn = tkinter.Button(
341+
root,
342+
text="Start",
343+
width=30,
344+
borderwidth=10,
345+
fg="#000000",
346+
bg="#99ffd6",
347+
font=("", 13),
348+
cursor="hand2",
349+
command=disp_option,
350+
)
351+
start_btn.pack(pady=(50, 20))
352+
353+
354+
root.mainloop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import tkinter
2+
from tkinter.constants import END
3+
from tkinter.font import names
4+
import random
5+
from tkinter import Label, messagebox
6+
from typing import Text

0 commit comments

Comments
 (0)