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
#2
Failing that does anyone know the mechanics of how to do the spinning effect?
For example do you literally move each card(symbol) down a column? Or use parts of each symbol?
or use a strip of the symbols? I have no clue.

I have tried 3 symbol strip and placing half of two cards on one card to simulate the spin
but doesn't work, I just don't have a clue how it can work>
Reply
#3
google: 'tkinter rotation'
Reply
#4
I didn't find anything that made sense to me to make a reel spin, but I did come across
the canvas move attribute, which might play about with to see what happens.
https://www.geeksforgeeks.org/python-tki...ve-method/
Reply
#5
You could make one large image that is all the card images stacked on top of each other and scroll this image inside a frame that is only large enough to show 1 card. I don't think this will look like a spin though. You can probably get something that looks "spinny" if you placed a transition image between each card image. Something that looks like you are half way between cards

You should not be loading the same images over and over. Load them once at the start of the program and reuse the images. Reloading the image is slow, and you may have memory issues with the garbage collector falling behind all the trash you are making
steve_shambles likes this post
Reply
#6
Thanks deanhystad, that gives me something to work on.
Reply


Forum Jump:

User Panel Messages

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