May-18-2020, 12:33 AM
(This post was last modified: May-18-2020, 12:34 AM by deanhystad.)
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.
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:
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.