May-18-2020, 11:31 PM
Instead of deleting things you should reuse. I tried my best to follow the conventions you use in your program but I cannot force myself to not use a list when the code is SCREAMING for you to use a list. So instead of reel_one, reel_two and reel_three I use reel[].
def make_images(): card_images = {} for card in Glo.ranks: card_images[card] = PhotoImage(file='cards/gfx/'+card+'.png') return card_images def spin_reels(): """Pseudo spin, Best I can do for now. loading files on the fly uses a lot of memory, so need to fix this.""" disable_hold_btns() cards = list(Glo.card_images.values()) for reel in range(len(Glo.reel)): for _ in range(18): # Randomly display different images for i in range(len(Glo.reel)): if i >= reel and not Glo.hold_btn_is_held[i]: card = random.choice(cards) Glo.card_labels[reel].configure(image=card) Glo.card_labels[reel].update() time.sleep(0.025) # The reel is stopped. Display the final image card = Glo.card_images[Glo.reel[reel]] Glo.card_labels[reel].configure(image=card) Glo.card_labels[reel].update() check_for_win() rnd_hold() save_bank(reels) # Add this to initialization code. Maybe in the same place where you make # the hold buttons (once) and the hold button images (once) Glo.card_labels = = [Label(cards_frame), Label(cards_frame), Label(cards_frame)] Glo.card_images = make_images() def get_rnd_cards() """Randomly select cards for slots that are not held. Can only use a card once. """ # Get unused cards cards = Glo.ranks.copy() for i in range(len(Glo.reel)): if Glo.hold_btn_is_held[i]: cards.remove(Glo.reel[i]) # Choose from remaining cards for i in range(len(Glo.reel)): if not Glo.hold_btn_is_held[i]: card = random.choice(cards) Glo.reel[i] = card cards.remove(card)