For each winning item i would like to display its corresponding picture on the GUI. At the moment i am writing a bunch of code shown in the if statements to achieve this. I am sure i can use some sort of a loop to reduce the amount of code but unsure at this point how i can achieve this.
I am also having issues with removing the image after each non-winning roll. My current attempt at solving this is shown in the code provided within the else statement at the bottom.
chance_of_drop = random.randint(1,100)
if chance >= chance_of_drop:
winner = np.random.choice(Items, p=probabilities)
drop['text'] = "You've recieved a drop: " + winner
if winner == Items[0]:
Loot_IMG = PhotoImage(file=Images[0])
reward_img = Label(GUI, image = Loot_IMG, background = bg_color)
reward_img.Loot_IMG = Loot_IMG #
reward_img.grid(row = 3, column=1, sticky = N)
elif winner == Items[1]:
Loot_IMG = PhotoImage(file=Images[1])
reward_img = Label(GUI, image = Loot_IMG, background = bg_color)
reward_img.Loot_IMG = Loot_IMG #
reward_img.grid(row = 3, column=1, sticky = N)
elif winner == Items[2]:
Loot_IMG = PhotoImage(file=Images[2])
reward_img = Label(GUI, image = Loot_IMG, background = bg_color)
reward_img.Loot_IMG = Loot_IMG #
reward_img.grid(row = 3, column=1, sticky = N)
# AND SO ON.....
#print("You've recieved a drop:", winner)
else:
luck['text'] = "You are unlucky"
#REMOVING IMAGE DOES NOT WORK
Loot_IMG = PhotoImage(file="")
reward_img = Label(GUI, image = Loot_IMG, background = bg_color)
reward_img.Loot_IMG = Loot_IMG #
reward_img.grid(row = 3, column=1, sticky = N)
ALSO i will provide both of the lists i have constructed further up within the function:
Images = ["loot/Dexterous_prayer_scroll.png", "loot/Arcane_prayer_scroll.png",
"loot/Twisted_buckler.png", "loot/Dragon_hunter_crossbow.png",
"loot/Dinh's_bulwark.png", "loot/Ancestral_hat.png", "loot/Ancestral_robe_top.png",
"loot/Ancestral_robe_bottom.png", "loot/Dragon_claws.png", "loot/Elder_maul.png",
"loot/Kodai_insignia.png", "loot/Twisted_bow.png"]
# indivdual drop rates
Items = ["Dexterous prayer scroll", "Arcane prayer scroll",
"Twisted buckler", "Dragon hunter crossbow",
"Dinh's bulwark", "Ancestral hat", "Ancestral robe top",
"Ancestral robe bottom", "Dragon claws",
"Elder maul", "Kodai insignia", "Twisted bow"]