-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_game.py
More file actions
145 lines (118 loc) · 5.03 KB
/
python_game.py
File metadata and controls
145 lines (118 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import random
import tkinter as tk
from tkinter import *
from PIL import Image, ImageTk
i = 1
passing_imgnames = []
passing_imgrealnames = []
checkNames = []
li_urls = ['image_1.png', 'image_2.png', 'image_3.png', 'image_4.png',
'image.gif']
li_names = ['tree', 'glasses', 'flower', 'masked man', 'earth']
reelList = [['Apple', 'Umbrella', 'Water Bottle'], ['Mango', 'Television', 'Chair'],
['Pencil', 'Pizza', 'Wire'], ['Cup', 'Window', 'Peach'], ['Strawberry', 'Ball', 'Pillow']]
r = tk.Tk()
r.title('KIDS LEARNING GAME!')
tk.Label(r,
text="Welcome to the kids learning game.",
fg = "white",
bg = "#263D42",
font = "Helvetica 16 bold italic").pack()
canvas = tk.Canvas(r, height = 700, width = 700, bg = "#263D42" )
canvas.pack(expand = 'YES', fill = BOTH)
def takeInput():
import Validator as v
v.takeInputs()
def closeApp():
d=messagebox.askquestion("Confirm","Are you sure?")
if(d == 'yes'):
r.destroy()
def presentList(flag, getStr = ''):
if(flag == 0):
strg = 'Tree, Ball, glasses, Flower, Mango, Masked-man'
canvas.create_text(1200,200,fill="White",font="Helvetica 14 bold italic", text= strg)
else:
canvas.create_text(1200,230,fill="White",font="Helvetica 14 bold italic", text= getStr)
def insertInitialImages():
startButton.destroy()
quitButton.destroy()
strHead = 'Make your choice here!'
canvas.create_text(1200,150,fill="White",font="Helvetica 14 bold italic", text= strHead)
presentList(0)
startFunc()
img = Image.open(li_urls[0])
img = img.resize((350, 250), Image.ANTIALIAS)
canvas.image1 = ImageTk.PhotoImage(img)
canvas.create_image(300, 230, image = canvas.image1)
img1 = Image.open(li_urls[1])
img1 = img1.resize((350, 250), Image.ANTIALIAS)
canvas.image2 = ImageTk.PhotoImage(img1)
canvas.create_image(700, 230, image = canvas.image2)
img3 = Image.open(li_urls[2])
img3 = img3.resize((350, 250), Image.ANTIALIAS)
canvas.image4 = ImageTk.PhotoImage(img3)
canvas.create_image(300, 530, image = canvas.image4)
img4 = Image.open(li_urls[3])
img4 = img4.resize((350, 250), Image.ANTIALIAS)
canvas.image5 = ImageTk.PhotoImage(img4)
canvas.create_image(700, 530, image = canvas.image5)
def insertNewImages(img_names):
img = Image.open(img_names[0])
img = img.resize((350, 250), Image.ANTIALIAS)
canvas.image1 = ImageTk.PhotoImage(img)
canvas.create_image(300, 230, image = canvas.image1)
img1 = Image.open(img_names[1])
img1 = img1.resize((350, 250), Image.ANTIALIAS)
canvas.image2 = ImageTk.PhotoImage(img1)
canvas.create_image(700, 230, image = canvas.image2)
img3 = Image.open(img_names[2])
img3 = img3.resize((350, 250), Image.ANTIALIAS)
canvas.image4 = ImageTk.PhotoImage(img3)
canvas.create_image(300, 530, image = canvas.image4)
img4 = Image.open(img_names[3])
img4 = img4.resize((350, 250), Image.ANTIALIAS)
canvas.image5 = ImageTk.PhotoImage(img4)
canvas.create_image(700, 530, image = canvas.image5)
while len(passing_imgnames):
passing_imgnames.pop()
def itemShuffler(realList):
strg = ''
r1 = random.randint(0, 4)
li = realList + reelList[r1]
shuffledList = random.sample(li, len(li))
for i in shuffledList:
strg = strg + i.join(' ,')
presentList(1, strg)
while len(passing_imgrealnames) > 0:
passing_imgrealnames.pop()
def displayListOfNames(takeNames):
for i in takeNames:
if takeNames.index(i) > 4:
continue
else:
checkNames.append(takeNames.index(i))
for i in checkNames:
if i > 4:
continue
else:
passing_imgrealnames.append(li_names[i])
while len(checkNames) > 0:
checkNames.pop()
itemShuffler(passing_imgrealnames)
def funcRandomSelector():
for i in range(4):
passing_imgnames.append(str(random.choice(li_urls)))
displayListOfNames(passing_imgnames)
insertNewImages(passing_imgnames)
def startFunc():
quitButton1 = tk.Button(r, text = "QUIT", padx= 8, pady = 10, fg = 'white', bg = '#263D42', command = closeApp)
quitButton1.place(relx = 0.48, x = -3.5, y = 32.5, rely = 0.88)
refreshButton = tk.Button(r, text = "REFRESH", padx= 8, pady = 10, fg = 'white', bg = '#263D42', command = funcRandomSelector)
refreshButton.place(relx = 0.47, x = -3.5, y = 32.5, rely = 0.02)
playButton = tk.Button(r, text = "PLAY", padx= 8, pady = 10, fg = 'white', bg = '#263D42', command = takeInput)
playButton.place(relx = 0.765, x = -3.5, y = 32.5, rely = 0.02)
startButton = tk.Button(r, text = "START GAME", padx= 10, pady = 5, fg = 'white', bg = '#263D42', command = insertInitialImages)
startButton.place(relx = 0.45, rely = 0.7)
quitButton = tk.Button(r, text = "QUIT",padx= 10, pady = 5, fg = 'white', bg = '#263D42', command = closeApp)
quitButton.place(relx = 0.53, rely = 0.7)
r.mainloop()