from tkinter import *
import simpleaudio as sa
root = Tk()
root.title("FLAMES")
root.geometry("+100+0")
root.configure(bg="#000000")
root.resizable(width=False,height=False)
root.iconphoto(True,PhotoImage(file="flames.png"))
#Load audio files :
start = sa.WaveObject.from_wave_file("Start.wav")
one = sa.WaveObject.from_wave_file("Win.wav")
two = sa.WaveObject.from_wave_file("Lose.wav")
three = sa.WaveObject.from_wave_file("Draw.wav")
four = sa.WaveObject.from_wave_file("1.wav")
five = sa.WaveObject.from_wave_file("2.wav")
six = sa.WaveObject.from_wave_file("6.wav")
#Take input from user :
name1 = input("Player 1 name : ")
name1 = name1.upper()
# replace any space with empty string
name1.replace(" ", "")
# make a list of letters or characters
name1_list = list(name1)
# take 2nd name
name2 = input("Player 2 name : ")
name2 = name2.upper()
name2.replace(" ", "")
name2_list = list(name2)
#Set the longer name as name1 :
if len(name2)>len(name1):
name3 = name1
name1 = name2
name2 = name3
# Remove comman characters :
def remove_comman_char(list1, list2):
for i in range(len(list1)) :
for j in range(len(list2)) :
if list1[i] == list2[j] :
c = list1[i]
# Remove character from the list
list1.remove(c)
list2.remove(c)
# Concate two lists with # in middle
list3 = list1 + ["#"] + list2
# Return the concatenated list with True flag
return [list3, True]
# No common chcaracters found
list3 = list1 + ["#"] + list2
return [list3, False]
# Taking a flag as True initially
proceed = True
while proceed :
# Function call
ret_list = remove_comman_char(name1_list, name2_list)
#Final list :
con_list = ret_list[0]
#Flag value :
proceed = ret_list[1]
#Index of hash :
hash_index = con_list.index("#")
# all characters before * store in p1_list
name1_list = con_list[ : hash_index]
# all characters after * store in p2_list
name2_list = con_list[hash_index + 1 : ]
# count total remaining characters
count = len(name1_list) + len(name2_list)
# list of FLAMES acronym
result = ["Friends", "Lovers", "Affectionate", "Marriage", "Enemies", "Siblings"]
while len(result) > 1 :
ind = (count % len(result)) - 1
if ind >= 0 :
right = result[ind + 1 : ]
left = result[ : ind]
result = right + left
else :
result = result[ : len(result) - 1]
#Load images for tkinter window :
surprise = PhotoImage(file="Surprise.png")
fingers = PhotoImage(file="Fingers.png")
Friends = PhotoImage(file="F11.png")
Lovers = PhotoImage(file="L11.png")
Affectionate = PhotoImage(file="A11.png")
Marriage = PhotoImage(file="M11.png")
Enemies = PhotoImage(file="E11.png")
Siblings = PhotoImage(file="S11.png")
#Length of names :
n_1 = len(name1)
n_2 = len(name2)
#Creaate list of names :
l1 = list(name1)
l2 = list(name2)
#Load the letters for name1 :
for i in range(n_1):
l1[i] = PhotoImage(file=str(l1[i])+str(".png"))
#Load the letters for name2 :
for j in range(n_2):
l2[j] = PhotoImage(file=str(l2[j])+str(".png"))
r1=0
c1=0
r2=2
c2=0
#Display name1 :
for i in range(n_1):
B = Label(root,image=l1[i])
B.grid(row=r1,column=c1)
c1 = c1+1
#Add blank space :
root.grid_rowconfigure(1, minsize=50)
#Display name2 :
for j in range(n_2):
B = Label(root,image=l2[j])
B.grid(row=r2,column=c2)
c2 = c2+1
#Add blank space :
root.grid_rowconfigure(3, minsize=50)
#Add button :
btn = Button(root,image=surprise,command=lambda:Reveal())
btn.grid(row=4,column=0,columnspan = n_1)
#Add result label :
res = Label(root,image=fingers)
res.grid(row=6,column=0,columnspan = n_1)
#Add blank space :
root.grid_rowconfigure(5, minsize=50)
#Play sound file :
start.play()
#Reveal the result :
def Reveal():
if result[0]=="Friends":
one.play()
res.configure(image=Friends)
btn.configure(command=lambda:root.destroy())
elif result[0]=="Lovers":
five.play()
res.configure(image=Lovers)
btn.configure(command=lambda:root.destroy())
elif result[0]=="Affectionate":
six.play()
res.configure(image=Affectionate)
btn.configure(command=lambda:root.destroy())
elif result[0]=="Marriage":
four.play()
res.configure(image=Marriage)
btn.configure(command=lambda:root.destroy())
elif result[0]=="Enemies":
two.play()
res.configure(image=Enemies)
btn.configure(command=lambda:root.destroy())
else:
three.play()
res.configure(image=Siblings)
btn.configure(command=lambda:root.destroy())
root.mainloop()