jeuxdeau2009 0 Newbie Poster

Im writing a blackjack program to train one to count cards using the Hi-Lo System.

I found the engine online ( it was open sourced.) Instead of the code here using only numbers and Letters, i want to add only pictures of the cards instead of the numbers and card values. I need help. I recently downloaded pygame to help me import images. but i am having no luck.. Please take a look

#!/usr/bin/python

import Tkinter
import sys
import tkMessageBox
from random import shuffle
import pygame.image
import pygame.display

class cardTrainer:

    def __init__(self, master):

        #Define the deck of cards by list of representative strings
        self.deck = ['A', '2','3','4','5','6','7','8','9','10','J','K']            
        #Holds the current count
        self.current_count = 0

        #Holds the position in the deck of cards we got to
        self.current_card_position = 0

        #Boolean to hold weather the count loop is running
        self.count_running = False

        #Shuffle the cards
        shuffle(self.deck)

        #Define the Tkinter frame to hold the main interface
        frame = Tkinter.Frame(master)
        frame.pack(fill=Tkinter.X, expand=.5)

        #Define the interface


        self.label = Tkinter.Label(frame, text='BlackJack Card Counter')
        self.label.pack()


        self.slider = Tkinter.Scale(frame, from_=100, to=2000, orient=Tkinter.HORIZONTAL,
                                    showvalue=0, command=self.new_timerspeed)
        self.slider.set(2100)
        self.slider.pack(fill=Tkinter.X, expand=1)

        self.start = Tkinter.Button(frame, text='Deal', command=self.startDeal)
        self.start.pack()

        self.stop = Tkinter.Button(frame, text="Show count", command=self.stopDeal)
        self.stop.pack()

        self.exit = Tkinter.Button(frame, text="Quit", command=top.quit)
        self.exit.pack()

        self.label = Tkinter.Button(frame, text="Images", command=self.pic)
        self.label.pack()

    def startDeal(self):

        #Ignore button press if count is running
        if self.count_running == True:
            pass

        #Make the program know it's running
        self.count_running = True

        #Call the function that holds the main loop
        self.Deal()

    def pic(self):
         import pygame.display
         picture = pygame.image.load("ace.jpg")


    def Deal(self):

        if self.count_running == True:
            #Update label to show current card value
            self.label.config(text=self.deck[self.current_card_position])

            #Update the count value
            self.updateCount(self.deck[self.current_card_position])

            #Update the position in the deck we are at
            self.current_card_position += 1

            #if we have reached the end of the deck, shuffle and continue
            if self.current_card_position == len(self.deck):
                shuffle(self.deck)
                self.current_card_position = 0

            #Run this process again after a time period designated by the slider
            self.label.after(self.timerspeed, self.Deal)
        else:
            #update label to show that we finished and the last card value
            self.label.config(text = "The count has been stopped\n" +
                                self.deck[self.current_card_position])

            #Tell the user the count
            tkMessageBox.showinfo("The Count", "The count is:\n" + str(self.current_count))

            self.current_count = 0

    def updateCount(self, card):
        #Take the actual numerical value of the card
        card = card[1:]

        #Deine which Conditions make the count go up/down/stay the same
        self.conditions_up = ("A", "K", "Q", "J", "10")
        self.conditions_same=("7", "8", "9")
        self.conditions_down=("6", "5", "4", "3", "2")

        #Alter the count depending on which condition the card matches
        for value in self.conditions_up:
            if card == value:
                self.current_count -= 1
                break
        for value in self.conditions_same:
            if card == value:
                break
        for value in self.conditions_down:
            if card == value:
                self.current_count +=1
                break

    def stopDeal(self):
        #Make the main loop finish
        self.count_running = False

    def new_timerspeed(self, x):
        self.timerspeed = x

if __name__ == "__main__":
    top = Tkinter.Tk()
    top.geometry('500x500')
    app = cardTrainer(top)
    top.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.