I am building a simple game, spot the differences in which the images which be loaded up and the user fill find the differences in every picture after that he/ she will put their score mannualy, then after 5 pictures their total score will be shown out of 25, each 5 pictures are of 5 marks.
# CS PROJECT CLASS 12
#importing library
import os
from tkinter import*
from tkinter import PhotoImage
from PIL import ImageTk,Image
#from os import system, name
# import call method from subprocess module
from subprocess import call
# import sleep to show output for some time period
from time import sleep
user_scores = []
a1 = 0
a2 = 0
a3 = 0
a4 = 0
a5 = 0
#creating functions
def whatsup():
newl=Label(root_widget,text='Thank you for clicking on this game.This is how it is going to unfold')
newl.config(font=('Calibri',15))
newl.pack()
def game():
newl2=Label(root_widget,text='''You will be shown pictures in which you would have to count the
number of differences you find. The correct andwer and the total differences along with their answers
will be presented .''')
newl2.config(font=('Calibri',15))
newl2.pack()
#remeber the name of the person is e.get
def greeter():
mybutton3=Button(root_widget,text='Hello ' + e.get())
mybutton3.config(font=("Calibri", 15))
mybutton3.pack()
def quitting():
root_widget.destroy()
# define clear function
def clear1():
# TO CLEAR THE FIRST SCREEN
#Simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets()
#CLEARING SCREEN ONE TO SHOW ANSWER
def clear2():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets2()
# mylabel=Label(image=image1)
#Response function
def response():
return f.get
#BUTTON FUNCTION
def new_page_btn_1():
newl = Label(root_widget, text='Welcome to the new page')
newl.config(font=('Calibri', 15))
newl.pack()
#ADDING PICTURE 1
def add_new_widgets():
new_label = Label(root_widget, text="Find the differences in these pictures")
new_label.config(font=("Calibri", 20))
new_label.pack()
#adding next button
new_button1 = Button(root_widget, text="Next", command=clear2)
new_button1.config(font=("Calibri", 15))
new_button1.pack()
# adding the first picture
img = PhotoImage(file="C:\Users\samee\OneDrive\Desktop\f.png")
#panel = Label(root_widget, image = img)
frame = Frame(root_widget, width="200", height="200", bg="black")
frame.pack(pady=10) # Adding some padding around the frame
panel = Label(frame, image = img)
# panel.pack()
panel.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#adding a continue button
#continues=Button(root_widget, text='Answers',command=quitting,fg='red')
#continues.pack()
#NEW CODE TO ADD ANSWER FOR PICTURE ONE
def add_new_widgets2():
new_label2= Label(root_widget, text="Answer to picture one")
new_label2.config(font=("Calibri", 20))
new_label2.pack()
#label for no of differences
labelfordiff1=Label(root_widget,text='''There were 5 differences.
How many did you find?''')
labelfordiff1.config(font=("Calibri", 15))
labelfordiff1.pack()
#adding answer button 1
ans1=Entry(root_widget,width=50,fg='red',bg='white',borderwidth=13)
ans1.pack()
global user_scores
ans1 = ans1.get()
print(ans1)
if ans1: # Check if ans1 is not empty
user_scores.append(int(ans1))
# a1 = ans1.get()
# if a1 == '':
# ans1 = 0
# else:
# ans1 += int(a1)
#adding a new button
new_button2= Button(root_widget, text="Next image", command=clear3)#command 3 to be created
new_button2.config(font=("Calibri", 15))
new_button2.pack()
#adding answer image
img2 = PhotoImage(file="D:\C DATA\Downloads\differences1.png")
frame2 = Frame(root_widget, width="200", height="200", bg="black")
frame2.pack(pady=10) # Adding some padding around the frame
panel2 = Label(frame2, image = img2)
# panel.pack()
panel2.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#REMOVING ANSWER1
def clear3():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets3()
#ADDING PICTURE 2
def add_new_widgets3():
#adding label
picdiff2=Label(root_widget,text='Find the differences in these pictures')
picdiff2.config(font=("Calibri", 20))
picdiff2.pack()
#next button
new_button3= Button(root_widget, text="Next image", command=clear4)
#command 4 to be created
new_button3.config(font=("Calibri", 15))
new_button3.pack()
#adding new picture 2
img3 = PhotoImage(file="D:\C DATA\Downloads\ftd2.png")
#panel = Label(root_widget, image = img)
frame3 = Frame(root_widget, width="200", height="200", bg="black")
frame3.pack(pady=10)
# Adding some padding around the frame
panel3 = Label(frame3, image = img3)
panel3.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#TO REMOVE PICTURE ONE
def clear4():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets4()
#ADDING ANSWER TO PICTURE TWO
def add_new_widgets4():
answerpic2= Label(root_widget, text="Answer to picture two")
answerpic2.config(font=("Calibri", 20))
answerpic2.pack()
#label for no of differences
labelfordiff2=Label(root_widget,text='''There were 5 differences.
How many did you find?''')
labelfordiff2.config(font=("Calibri", 15))
labelfordiff2.pack()
#adding answer button 2
ans2=Entry(root_widget,width=50,fg='red',bg='white',borderwidth=13)
ans2.pack()
global user_scores
ans2 = ans2.get()
if ans2: # Check if ans1 is not empty
user_scores.append(int(ans2))
# a2 = ans2.get()
# if a2 == '':
# ans2 = 0
# else:
# ans2 += int(a2)
#adding a new button
new_button3= Button(root_widget, text="Next", command=clear5)#command 3 to be created
new_button3.config(font=("Calibri", 15))
new_button3.pack()
#adding answer image
img4 = PhotoImage(file="D:\C DATA\Downloads\differences2.png")
frame4 = Frame(root_widget, width="200", height="200", bg="black")
frame4.pack(pady=10) # Adding some padding around the frame
panel4 = Label(frame4, image = img4)
# panel.pack()
panel4.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#REMOVING ANSWER 2
def clear5():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets5()
#TO REMOVE PICTURE 3
def clear6():
#simply destroying all the widgets
#add_new_widgets6()
for widget in root_widget.winfo_children():
widget.destroy()
add_new_widgets6()
#ADDING PICTURE 3
def add_new_widgets5():
addpic3= Label(root_widget, text="Find the differences")
addpic3.config(font=("Calibri", 20))
addpic3.pack()
#adding a new button to move to the answer
buttonz=Button(root_widget,text='Next',command=clear6)
buttonz.config(font=("Calibri", 15))
buttonz.pack()
#adding photo image
img5 = PhotoImage(file="D:\C DATA\Downloads\ftd3.png")
frame5 = Frame(root_widget, width="200", height="200", bg="black")
frame5.pack(pady=10) # Adding some padding around the frame
panel5 = Label(frame5, image = img5)
# panel.pack()
panel5.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#ADDING ANSWER 3
def add_new_widgets6():
answerpic3= Label(root_widget, text="Answer to picture three")
answerpic3.config(font=("Calibri", 20))
answerpic3.pack()
#label for no of differences
labelfordiff3=Label(root_widget,text='''There were 5 differences.
How many did you find?''')
labelfordiff3.config(font=("Calibri", 15))
labelfordiff3.pack()
#adding answer button 3
ans3=Entry(root_widget,width=50,fg='red',bg='white',borderwidth=13)
ans3.pack()
global user_scores
ans3 = ans3.get()
if ans3: # Check if ans1 is not empty
user_scores.append(int(ans3))
# a3 = ans3.get()
# if a3 == '':
# ans3 = 0
# else:
# ans3 += int(a3)
#adding a new button
new_button4= Button(root_widget, text="Next", command=clear7)#command 7 to be created
new_button4.config(font=("Calibri", 15))
new_button4.pack()
#adding answer image
img6 = PhotoImage(file="D:\C DATA\Downloads\differences3.png")
frame6= Frame(root_widget, width="200", height="200", bg="black")
frame6.pack(pady=10) # Adding some padding around the frame
panel6 = Label(frame6, image = img6)
# panel.pack()
panel6.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#TO REMOVE ANSWER 3
def clear7():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets7()
#ADDING PICTURE 4
def add_new_widgets7():
addpic4= Label(root_widget, text="Find the differences")
addpic4.config(font=("Calibri", 20))
addpic4.pack()
#adding a new button
new_buttonZ= Button(root_widget, text="Next", command=clear8)#command 8 to be created
new_buttonZ.config(font=("Calibri", 15))
new_buttonZ.pack()
#adding photo image
img7 = PhotoImage(file="D:\C DATA\Downloads\ftd4.png")
frame7 = Frame(root_widget, width="200", height="200", bg="black")
frame7.pack(pady=10) # Adding some padding around the frame
panel7 = Label(frame7, image = img7)
# panel.pack()
panel7.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#ADDING ANSWER 4
def add_new_widgets8():
answerpic4= Label(root_widget, text="Answer to picture four")
answerpic4.config(font=("Calibri", 20))
answerpic4.pack()
#label for no of differences
labelfordiff4=Label(root_widget,text='''There were 5 differences.
How many did you find?''')
labelfordiff4.config(font=("Calibri", 15))
labelfordiff4.pack()
#adding answer button 4
ans4=Entry(root_widget,width=50,fg='red',bg='white',borderwidth=13)
ans4.pack()
global user_scores
ans4 = ans4.get()
if ans4: # Check if ans1 is not empty
user_scores.append(int(ans4))
# a4 = ans4.get()
# if a4 == '':
# ans4 = 0
# else:
# ans4 += int(a4)
#adding a new button
new_buttonm= Button(root_widget, text="Next", command=clear9)#command 9 to be created
new_buttonm.config(font=("Calibri", 15))
new_buttonm.pack()
#adding answer image
img8 = PhotoImage(file="D:\C DATA\Downloads\differences4.png")
frame8= Frame(root_widget, width="200", height="200", bg="black")
frame8.pack(pady=10) # Adding some padding around the frame
panel8 = Label(frame8, image = img8)
# panel.pack()
panel8.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#CLEARING PICTURE 5
def clear10():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets10()
#ADDING PICTURE 5
def add_new_widgets9():
addpic5= Label(root_widget, text="Find the differences")
addpic5.config(font=("Calibri", 20))
addpic5.pack()
#adding a new button
new_buttonss= Button(root_widget, text="Next", command=clear10)#command 10 to be created
new_buttonss.config(font=("Calibri", 15))
new_buttonss.pack()
#adding photo image
img9 = PhotoImage(file="D:\C DATA\Downloads\ftd5.png")
frame9 = Frame(root_widget, width="200", height="200", bg="black")
frame9.pack(pady=10) # Adding some padding around the frame
panel9 = Label(frame9, image = img9)
# panel.pack()
panel9.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#ADDING ANSWER5
def add_new_widgets10():
answerpic5= Label(root_widget, text="Answer to picture five")
answerpic5.config(font=("Calibri", 20))
answerpic5.pack()
#label for no of differences
labelfordiff5=Label(root_widget,text='''There were 5 differences.
How many did you find?''')
labelfordiff5.config(font=("Calibri", 15))
labelfordiff5.pack()
#adding answer button 5
ans5=Entry(root_widget,width=50,fg='red',bg='white',borderwidth=13)
ans5.pack()
global user_scores
ans5 = ans5.get()
if ans5: # Check if ans1 is not empty
user_scores.append(int(ans5))
# a5 = ans5.get()
# if a5 == '':
# ans5 = 0
# else:
# ans5 += int(a5)
#adding a new button
new_buttonb= Button(root_widget, text="Next", command=clear11)#command 11 to be created
new_buttonb.config(font=("Calibri", 15))
new_buttonb.pack()
#adding answer image
img10 = PhotoImage(file="D:\C DATA\Downloads\differences5.png")
#"C:UserssameeOneDriveDesktopdifferences5.png"4
frame10= Frame(root_widget, width="200", height="200", bg="black")
frame10.pack(pady=10) # Adding some padding around the frame
panel10 = Label(frame10, image = img10)
# panel.pack()
panel10.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
mylabel.pack()
#REMOVING ANSWER 5
def clear11():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
endthis()
def endthis():
imdone=Label(root_widget,text='''CONGRATULATIONS
YOU SUCCESSFULLY COMPLETED THIS GAME.''')
imdone.config(font=("Calibri", 30))
imdone.pack()
finalbutton=Button(root_widget,text='Click for score-',command=showscore)
finalbutton.config(font=("Calibri", 15))
finalbutton.pack()
def showscore():
# a=a1+a2+a3+a4+a5
# print("a1, a2, a3, a4, a5:", a1, a2, a3, a4, a5)
total_score = sum(user_scores)
print("User scores:", user_scores)
# b=str(a)
showit = Label(root_widget, text=f"You scored {total_score} out of 25! Well done.")
showit.config(font=("Calibri", 30))
showit.pack()
#CLEAR ANSWER 4
def clear9():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets9()
#CLEARING PICTURE 4
def clear8():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets8()
#REMOVING PICTURE 3
def clear6():
#simply destroying all the widgets
for widget in root_widget.winfo_children():
widget.destroy()
#newroot_widget=root_widget.winfo_children()
add_new_widgets6()
#****************************************************************************************************************************************************************
#STARTING OF MAIN PROGRAM
#creating root window or widget
root_widget=Tk()
#title
root_widget.title('Spot the differences game by Sameesha Singh')
abc=Label(root_widget,text='''Basic instructions-the player will be shown two pictures containing slight differences.
Count the number of differences found and click answer for the answer.''')
abc.pack()
imgfortitle = PhotoImage(file="D:\C DATA\Downloads\title page image.png")
frame0 = Frame(root_widget, width="200", height="200", bg="black")
frame0.pack(pady=10) # Adding some padding around the frame
panel0 = Label(frame0, image = imgfortitle)
# panel.pack()
panel0.pack(side = "top", fill = "both", expand = "no",padx=10,pady=10)
#change the default feather icon
photo = PhotoImage(file = "D:\C DATA\Downloads\icon.png")
#creating labels
mylabel=Label(root_widget,text='Spot the differences')
mylabel.config(font=("Calibri", 30))
mylabel.pack()
mylabel2=Label(root_widget,text="What is your name?")
mylabel2.config(font=("Calibri", 20))
mylabel2.pack()
#creating an entry widget
e=Entry(root_widget,width=50,fg='blue',bg='white',borderwidth=13)
e.pack()
name=e.get()
#Deciding window size
root_widget.geometry('955x789')
#minsize and maxsize
root_widget.maxsize(2000,1000)
root_widget.minsize(955,789)
#attempting to clear the window and make space
clearscreen=Button(root_widget,text='Click to start game', command=clear1)
clearscreen.config(font=("Calibri", 15))
clearscreen.pack()
#exit permissions
button_quit=Button(root_widget,text='I want to exit',command=quitting)
button_quit.config(font=("Calibri", 9))
button_quit.pack()
root_widget.mainloop()
in this code the total user score is not being calculated, its 0 eveytime, score are not adding in the user score list as well. please help to solve this issue. i want the total score out of 25 at last.
11