Python Forum
How can I make the cards look like they are spinning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make the cards look like they are spinning
#1
"""Spinning reel test. Small working example.

   How can I make the cards look like they are spinning,
   like in a real slot machine? There will be 5 reels
   in the game eventually.

   Also, how do I make sure the card images do not eat
   up memory when thet are re-called time and again?
"""
import time
from tkinter import Tk, Frame, Label, PhotoImage

root = Tk()
root.geometry("300x300")
cards_frame = Frame(root)
cards_frame.grid()

def change_card(filename):
    """Spin reel one. Pass filename to photoimage and display."""
    reel_one = Label(cards_frame)
    PHOTO = PhotoImage(file=filename)
    reel_one.config(image=PHOTO)

    reel_one.grid(row=0, column=0)
    reel_one.photo = PHOTO
    reel_one.update()
    time.sleep(0.1)

def spin_reels():
    """Pass 3 card images 10 times to be displayed,
       will be random cards in game."""
    for spins in range(9):
        change_card(r'cards/AH.png')
        change_card(r'cards/KD.png')
        change_card(r'cards/QC.png')


spin_reels()
The cards folder can be found on github, vsmall download.
https://github.com/steveshambles/spin-re...in-test.py

This related to my Slot machine, Freespin Frenzy,
https://github.com/steveshambles/Freespin-Frenzy

but I want to build a new slot from scratch with 5 reels, but I
have to get these two problems sorted before i can start.
https://python-forum.io/Thread-Gui-slot-...mory-error
Thanks for any help.
Reply


Messages In This Thread
How can I make the cards look like they are spinning - by steve_shambles - Dec-21-2020, 08:55 AM

Forum Jump:

User Panel Messages

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