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
#8
You are printing out the name python is using to reference the image. Since the program does not provide an attribute name these are being generated automatically. It doesn't matter what they are called because you would reference images using an index into the images array.

If you would rather refer to the images using names like 'FW' or 'BC', the images could be placed in a dictionary.
from tkinter import Tk, PhotoImage
root = Tk()
 
spinner = ['FH', 'FD', 'FC',
           'WH', 'WD', 'WC',
           'JH', 'JD', 'JC', 'JS',
           'QH', 'QD', 'QC', 'QS',
           'KH', 'KD', 'KC', 'KS',
           'AH', 'AD', 'AC', 'AS',
           'BH', 'BD', 'BC']
images = {}
for name in spinner:
    images[name] = PhotoImage(file='cards/gfx/'+name+'.png')
 
print(images['BH'])
I notice a similar preference for individual variables is shown in your use of r_one, r_two, r_three and hold_btn1, hold_btn2, etc... Your slot machine has 3 reels and 3 hold buttons. Your code should have variables like reel_labels[] and hold_buttons[] and reel_pos[]. Other than where it appears in the window is there any difference between r_one and r_three? By treating the buttons and the reels generically, the amount of code will decrease and will be easier to understad

By using individual variables you make your code much more complicated. For example, I think the spin reel code could be reduced to something like this:
def spin_reels():
    """Spin the reels"""
    for _ in range(18):
        for i in range(len(reel_labels)):
            if not hold[i]: # Don't spin a held reel
                reel[i] = randrange(len(spinner_images)):
                reel_label[i].config(image=spinner_images[reel[i]])
        time.sleep(0.025)
I don't understand how the game plays with 4 spins and hold buttons so this could be completely wrong. This spin_reels randomly spins the three reels 18 times and remembers the last image in reel[]. If reel[0] = 3, the image displayed is WH.png. If there are multiple spins you would call the function multiple times. To lock a wheel you set hold[I] = True.
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, 12:33 AM

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