1
+ from tkinter import *
2
+ import random
3
+ from tkinter import messagebox
4
+
5
+ real_word = [
6
+ "GOAT" ,
7
+ "BOAT" ,
8
+ "RAIN" ,
9
+ "CODE" ,
10
+ "DISH" ,
11
+ "FISH" ,
12
+ "WASH" ,
13
+ "HAIR" ,
14
+ "NOSE" ,
15
+ "HAND" ]
16
+
17
+ jumbled_word = [
18
+ "AOGT" ,
19
+ "TOAB" ,
20
+ "INRA" ,
21
+ "DECO" ,
22
+ "DHIS" ,
23
+ "SHFI" ,
24
+ "SWAH" ,
25
+ "IRHA" ,
26
+ "SENO" ,
27
+ "NDHA" ]
28
+
29
+ options = random .randrange (0 ,len (jumbled_word ),1 )
30
+
31
+ def one ():
32
+ global jumbled_word , real_word ,options
33
+ lbl1 .config (text = jumbled_word [options ])
34
+
35
+ def answer ():
36
+ global jumbled_word ,real_word ,options
37
+ options = random .randrange (0 ,len (jumbled_word ),1 )
38
+ lbl1 .config (text = jumbled_word [options ])
39
+ e1 .delete (0 ,END )
40
+
41
+ def correct ():
42
+ global jumbled_word ,real_word ,options
43
+ one_var = e1 .get ()
44
+ if one_var == real_word [options ]:
45
+ messagebox .showinfo ("congratulations!" ,"your answer is correct." )
46
+ answer ()
47
+ else :
48
+ messagebox .showinfo ("sorry!" ,"Better luck next time." )
49
+ e1 .delete (0 ,END )
50
+
51
+
52
+ window = Tk ()
53
+ window .geometry ("350x400+400+300" )
54
+ window .title ("Jumbled Words Game" )
55
+ window .configure (background = "yellow" )
56
+
57
+ lbl1 = Label (window ,text = "write here" ,font = ("Arial" ,25 ,"bold" ),bg = "black" ,fg = "white" )
58
+ lbl1 .pack (pady = 30 ,ipady = 10 ,ipadx = 10 )
59
+
60
+ correct_1 = StringVar ()
61
+ e1 = Entry (window ,font = ("Arial" ,25 ,"bold" ),textvariable = correct_1 )
62
+ e1 .pack (ipady = 5 ,ipadx = 5 )
63
+
64
+ correct_button = Button (window ,text = "Check Out" ,font = ("Arial" ,20 ,"bold" ),width = 20 ,bg = "red" ,fg = "white" ,relief = GROOVE ,command = correct )
65
+ correct_button .pack (pady = 40 )
66
+
67
+ reset_button = Button (window ,text = "Reset" ,font = ("Arial" ,20 ,"bold" ),width = 20 ,bg = "blue" ,fg = "white" ,relief = GROOVE ,command = answer )
68
+ reset_button .pack ()
69
+
70
+ one ()
71
+ window .mainloop ()
0 commit comments