Python Forum
Gui slot machine-out of memory error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gui slot machine-out of memory error
#13
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)
Reply


Messages In This Thread
RE: Gui slot machine-out of memory error - by Yoriz - May-17-2020, 01:49 PM
RE: Gui slot machine-out of memory error - by Yoriz - May-17-2020, 02:05 PM
RE: Gui slot machine-out of memory error - by deanhystad - May-18-2020, 11:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 2,092 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  Memory Error While generating cheksum no mg24 2 1,031 Sep-25-2022, 10:33 PM
Last Post: mg24
  Help For Slot Machine Code Rayaan 1 2,707 Mar-30-2020, 05:01 AM
Last Post: SheeppOSU
  Memory consumption grows during execution only on single machine Jendker 2 1,877 Feb-10-2020, 01:57 PM
Last Post: Jendker
  Go around memory error Pytonormen 1 2,078 Oct-19-2019, 04:31 PM
Last Post: Gribouillis
  memory error using permutation list of 11 elements kikidog 1 3,891 Sep-10-2019, 08:22 PM
Last Post: ichabod801
  machine learning error (using jupyter) calonia 1 4,143 Jun-26-2019, 05:16 PM
Last Post: ThomasL
  Fix Memory Error while installing a library for Qgis alexastorga 0 2,584 Apr-13-2018, 04:54 PM
Last Post: alexastorga
  Dictionaries and memory error. jarrod0987 5 5,510 Feb-23-2018, 12:15 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020