Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### playing cards url... instructions: see below...
- ### https://www.dropbox.com/scl/fi/2lm6qoda3u8sosvmtxgrj/cards.zip?rlkey=mhs2xaay1b5n5r7lwv43g05c1&e=1&st=e0pjqijv&dl=0
- from tkinter import *
- import random
- from PIL import Image, ImageTk
- from tkinter import messagebox
- from tkinter.simpledialog import askstring
- import os, sys
- root = Tk()
- root.title('Blackjack - Card Deck')
- root.configure(background="green")
- ### Root Geometry width and height...
- frame_width = 800
- frame_height = 800
- current_dimensions = [frame_width, frame_height]
- root.geometry(f'{frame_width}x{frame_height}')
- def open_geo():
- # Increase the width by 100 pixels
- current_dimensions[0] += 100
- # Update the window geometry
- root.geometry(f'{current_dimensions[0]}x{current_dimensions[1]}')
- def resource_path(relative_path):
- try:
- base_path = sys._MEIPASS
- except Exception:
- base_path = os.path.abspath(".")
- return os.path.join(base_path, relative_path)
- def stand_H17():
- global player_total, dealer_total, player_score, d_aces, p_aces, enter1
- global split_score, split_total, data
- split_hit_button.config(state="disabled")
- split_button.config(state="disabled")
- split_double_button.config(state="disabled")
- card_button.config(state="disabled")
- double_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- # Keep track of score totals
- player_total = 0
- dealer_total = 0
- split_total = 0
- d_aces = 0
- p_aces = 0
- s_aces = 0
- enter1 = False
- data = []
- # Get the dealers score total
- for score in dealer_score:
- if score == 11:
- d_aces += 1
- dealer_total += score
- if d_aces > 0 and dealer_total > 21:
- dealer_total -= 10
- d_aces -= 1
- if d_aces > 0 and dealer_total > 21:
- dealer_total -= 10
- d_aces -= 1
- # Loop thru player score list and add up cards
- for score in player_score:
- if score == 11:
- p_aces += 1
- # print("p" + str(score))
- player_total += score
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- # print(int(player_total))
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- # Loop thru player score list and add up cards
- for score in split_score:
- if score == 11:
- s_aces += 1
- #print("s" + str(score))
- split_total += score
- #print(split_total)
- if s_aces > 0 and split_total > 21:
- split_total -= 10
- s_aces -= 1
- if s_aces > 0 and split_total > 21:
- split_total -= 10
- s_aces -= 1
- # Freeze the buttons
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- # Logic
- # Ensure values are integers
- player_total = int(player_total)
- dealer_total = int(dealer_total)
- # Check if the dealer has reached at least 17
- if dealer_total >= 17 and d_aces == 0:
- enter1 = True
- if dealer_total >= 18:
- enter1 = True
- if enter1 == True:
- # Check if player busts
- if player_total > 21:
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("Player Busts", f"Player Busts! Dealer: {dealer_total} Player: {player_total}")
- # Check if player has a Blackjack
- elif player_total == 21:
- if len(player_score) == 2: # Assuming player_score is the list of player's cards
- dealer_label_1.config(image=dealer_image1)
- cal_ace()
- messagebox.showinfo("", "Player Blackjack")
- elif player_total == 21 and dealer_total == 21:
- cal_tie()
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("its a tie!!", f"its a tie! Dealer: {dealer_total} Player: {player_total}")
- else:
- # Handle 21 but not a Blackjack (e.g., player has more than 2 cards)
- dealer_label_1.config(image=dealer_image1)
- cal_add() # Custom function if needed
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check if dealer busts
- elif dealer_total > 21:
- dealer_label_1.config(image=dealer_image1)
- cal_add()
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check for a tie
- elif dealer_total == player_total and player_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- cal_tie() # Custom function if needed
- messagebox.showinfo("Tie!!", f"It's a Tie!! Dealer: {dealer_total} Player: {player_total}")
- # Check if dealer wins
- elif dealer_total > player_total and dealer_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("Dealer Wins!!", f"Dealer Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check if player wins
- elif player_total > dealer_total and player_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- cal_add() # Custom function if needed
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Ensure values are integers
- split_total = int(split_total)
- if split_total > 0:
- if split_total > 21:
- messagebox.showinfo("Split Busts", f"Split Busts! Dealer: {dealer_total} Split: {split_total}")
- # Check if player has a Blackjack
- elif split_total == 21:
- if len(split_score) == 2: # Assuming player_score is the list of player's cards
- cal_ace_split() # Custom function for Blackjack
- messagebox.showinfo("", "Split Blackjack")
- else:
- # Handle 21 but not a Blackjack (e.g., player has more than 2 cards)
- cal_add_split() # Custom function if needed
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check if dealer busts
- elif dealer_total > 21:
- cal_add_split()
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check for a tie
- elif dealer_total == split_total and split_total <= 21:
- cal_tie_split() # Custom function if needed
- messagebox.showinfo("Tie!!", f"It's a Tie!! Dealer: {dealer_total} Split: {split_total}")
- # Check if dealer wins
- elif dealer_total > split_total and dealer_total <= 21:
- messagebox.showinfo("Dealer Wins!!", f"Dealer Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check if player wins
- elif split_total > dealer_total and split_total <= 21:
- cal_add() # Custom function if needed
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- else:
- # Add Card To Dealer
- if int(dealer_total) == 17 and d_aces > 0:
- dealer_hit()
- if int(dealer_total) < 17:
- dealer_hit()
- stand_H17()
- def stand_S17():
- global player_total, dealer_total, player_score, d_aces, p_aces
- global split_score, split_total
- split_hit_button.config(state="disabled")
- split_button.config(state="disabled")
- split_double_button.config(state="disabled")
- card_button.config(state="disabled")
- double_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- # Keep track of score totals
- player_total = 0
- dealer_total = 0
- split_total = 0
- d_aces = 0
- p_aces = 0
- s_aces = 0
- # Get the dealers score total
- for score in dealer_score:
- if score == 11:
- d_aces += 1
- dealer_total += score
- if d_aces > 0 and dealer_total > 21:
- dealer_total -= 10
- d_aces -= 1
- if d_aces > 0 and dealer_total > 21:
- dealer_total -= 10
- d_aces -= 1
- # Loop thru player score list and add up cards
- for score in player_score:
- if score == 11:
- p_aces += 1
- # print("p" + str(score))
- player_total += score
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- # print(int(player_total))
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- # Loop thru player score list and add up cards
- for score in split_score:
- if score == 11:
- s_aces += 1
- #print("s" + str(score))
- split_total += score
- #print(split_total)
- if s_aces > 0 and split_total > 21:
- split_total -= 10
- s_aces -= 1
- if s_aces > 0 and split_total > 21:
- split_total -= 10
- s_aces -= 1
- # Freeze the buttons
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- # Logic
- # Ensure values are integers
- player_total = int(player_total)
- dealer_total = int(dealer_total)
- # Check if the dealer has reached at least 17
- if dealer_total >= 17:
- # Check if player busts
- if player_total > 21:
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("Player Busts", f"Player Busts! Dealer: {dealer_total} Player: {player_total}")
- # Check if player has a Blackjack
- elif player_total == 21:
- if len(player_score) == 2: # Assuming player_score is the list of player's cards
- dealer_label_1.config(image=dealer_image1)
- cal_ace()
- messagebox.showinfo("", "Player Blackjack")
- elif player_total == 21 and dealer_total == 21:
- cal_tie()
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("its a tie!!", f"its a tie! Dealer: {dealer_total} Player: {player_total}")
- else:
- # Handle 21 but not a Blackjack (e.g., player has more than 2 cards)
- dealer_label_1.config(image=dealer_image1)
- cal_add() # Custom function if needed
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check if dealer busts
- elif dealer_total > 21:
- dealer_label_1.config(image=dealer_image1)
- cal_add()
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check for a tie
- elif dealer_total == player_total and player_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- cal_tie() # Custom function if needed
- messagebox.showinfo("Tie!!", f"It's a Tie!! Dealer: {dealer_total} Player: {player_total}")
- # Check if dealer wins
- elif dealer_total > player_total and dealer_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("Dealer Wins!!", f"Dealer Wins! Dealer: {dealer_total} Player: {player_total}")
- # Check if player wins
- elif player_total > dealer_total and player_total <= 21:
- dealer_label_1.config(image=dealer_image1)
- cal_add() # Custom function if needed
- messagebox.showinfo("Player Wins!!", f"Player Wins! Dealer: {dealer_total} Player: {player_total}")
- # Ensure values are integers
- split_total = int(split_total)
- if split_total > 0:
- if split_total > 21:
- messagebox.showinfo("Split Busts", f"Split Busts! Dealer: {dealer_total} Split: {split_total}")
- # Check if player has a Blackjack
- elif split_total == 21:
- if len(split_score) == 2: # Assuming player_score is the list of player's cards
- cal_ace_split() # Custom function for Blackjack
- messagebox.showinfo("", "Split Blackjack")
- else:
- # Handle 21 but not a Blackjack (e.g., player has more than 2 cards)
- cal_add_split() # Custom function if needed
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check if dealer busts
- elif dealer_total > 21:
- cal_add_split()
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check for a tie
- elif dealer_total == split_total and split_total <= 21:
- cal_tie_split() # Custom function if needed
- messagebox.showinfo("Tie!!", f"It's a Tie!! Dealer: {dealer_total} Split: {split_total}")
- # Check if dealer wins
- elif dealer_total > split_total and dealer_total <= 21:
- messagebox.showinfo("Dealer Wins!!", f"Dealer Wins! Dealer: {dealer_total} Split: {split_total}")
- # Check if player wins
- elif split_total > dealer_total and split_total <= 21:
- cal_add() # Custom function if needed
- messagebox.showinfo("Split Wins!!", f"Split Wins! Dealer: {dealer_total} Split: {split_total}")
- else:
- # Add Card To Dealer
- if int(dealer_total) < 17:
- # print(int(dealer_total))
- dealer_hit()
- # Recalculate Stuff
- stand_S17()
- def blackjack_shuffle(player):
- global player_total, dealer_total, player_score, dealer_score, blackjack_status, data
- # Keep track of score totals
- player_total = 0
- dealer_total = 0
- # Ensure player_score and dealer_score are defined and populated
- if player == "dealer":
- if len(dealer_score) == 2 and sum(dealer_score) == 21:
- # Update status
- blackjack_status["dealer"] = "yes"
- if player == "player":
- if len(player_score) == 2 and sum(player_score) == 21:
- # Update status
- blackjack_status["player"] = "yes"
- # Check for Push/Tie
- if len(dealer_score) == 2 and len(player_score) == 2:
- if blackjack_status["dealer"] == "yes" and blackjack_status["player"] == "yes":
- dealer_label_1.config(image=dealer_image1)
- cal_tie()
- messagebox.showinfo("Push!", "It's a Tie!")
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- elif blackjack_status["dealer"] == "yes":
- dealer_label_1.config(image=dealer_image1)
- if not card_button.cget('state') == 'disabled': # Only show message if it hasn't already been disabled
- messagebox.showinfo("Dealer Wins!", "Blackjack! Dealer Wins!")
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- elif blackjack_status["player"] == "yes":
- dealer_label_1.config(image=dealer_image1)
- cal_ace()
- messagebox.showinfo("Player Wins!", "Blackjack! Player Wins!")
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- # Ensure data is collected and uploaded
- data = [bankroll1.get(), playerbet1.get(), var1.get(), var2.get()]
- mydata_upload() # Save the data at the end of the function
- def player_bust():
- global score, player_score, player_total, p_aces
- score = 0
- p_aces = 0
- player_total = 0
- for score in player_score:
- if score == 11:
- p_aces += 1
- # print("score " + str(score))
- # print("ps " + str(player_score))
- player_total += score
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- # print("pt" + str(player_total))
- # print("Aces " + str(p_aces))
- if p_aces > 0 and player_total > 21:
- player_total -= 10
- p_aces -= 1
- if player_total > 21:
- dealer_label_1.config(image=dealer_image1)
- messagebox.showinfo("Player Busts", f"Player Busts: player: {player_total}")
- card_button.config(state="disabled")
- stand_button.config(state="disabled")
- deal_button.config(state="active")
- split_button.config(state="disabled")
- # Ensure data is collected and uploaded
- data = [bankroll1.get(), playerbet1.get(), var1.get(), var2.get()]
- mydata_upload() # Save the data at the end of the function
- def resize_cards(card):
- # Open the image
- our_card_img = Image.open(card)
- # Resize The Image
- our_card_resize_image = our_card_img.resize((100, 145)) # 150, 218
- # output the card
- global our_card_image
- our_card_image = ImageTk.PhotoImage(our_card_resize_image)
- # Return that card
- return our_card_image
- def shuffle():
- global Rc, deck, n_decks, shcount
- Rc = 0 # running count
- # Define Our Deck
- suits = ["diamonds", "clubs", "hearts", "spades"]
- values = range(2, 15)
- # 11 = Jack, 12=Queen, 13=King, 14 = Ace
- deck =[]
- i = 0
- for i in range(int(n_decks)):
- for suit in suits:
- for value in values:
- deck.append(f'{value}_of_{suit}') # value_of_suit
- root.title(f'Blackjack - {len(deck)/52} Decks Left')
- def deal():
- # Keep track of winning
- global blackjack_status, player_total, dealer_total, input1, input2
- global p_aces, d_aces, Rc, answer, split1
- # Keep track of score totals
- player_total = 0
- dealer_total = 0
- d_aces = 0
- p_aces = 0
- # bankroll1.delete(0,END)
- # bankroll1.insert(0,1000)
- if root.winfo_width() > 800:
- root.geometry(f'{frame_width}x{frame_height}')
- if len(deck) <= 40:
- messagebox.showinfo("", "need to shuffle soon")
- split_button.config(state="active")
- card_button.config(state="active")
- double_button.config(state="active")
- split_hit_button.config(state="disabled")
- split_double_button.config(state="disabled")
- deal_button.config(state="disabled")
- blackjack_status = {"dealer":"no", "player":"no"}
- # Enable buttons
- card_button.config(state="normal")
- stand_button.config(state="normal")
- # Clear all the old cards from previous games
- dealer_label_1.config(image='')
- dealer_label_2.config(image='')
- dealer_label_3.config(image='')
- dealer_label_4.config(image='')
- dealer_label_5.config(image='')
- dealer_label_6.config(image='')
- dealer_label_7.config(image='')
- dealer_label_8.config(image='')
- dealer_label_9.config(image='')
- dealer_label_10.config(image='')
- player_label_1.config(image='')
- player_label_2.config(image='')
- player_label_3.config(image='')
- player_label_4.config(image='')
- player_label_5.config(image='')
- player_label_6.config(image='')
- player_label_7.config(image='')
- player_label_8.config(image='')
- player_label_9.config(image='')
- player_label_10.config(image='')
- split_label_1.config(image='')
- split_label_2.config(image='')
- split_label_3.config(image='')
- split_label_4.config(image='')
- split_label_5.config(image='')
- split_label_6.config(image='')
- split_label_7.config(image='')
- split_label_8.config(image='')
- split_label_9.config(image='')
- split_label_10.config(image='')
- # Create our players
- global dealer, player, split1, split_spot, split_score, dealer_spot, player_spot, dealer_score, player_score
- global bank1, bet1
- dealer = []
- player = []
- split1 = []
- dealer_score = []
- player_score = []
- split_score = []
- dealer_spot = 0
- player_spot = 0
- split_spot = 0
- if playerbet1.get() == "0":
- messagebox.showinfo("", "you must bet first")
- deal_button.config(state="active")
- else:
- cal_sub()
- # Shuffle Two Cards for player and dealer
- dealer_hit()
- dealer_hit()
- player_hit()
- player_hit()
- blackjack_shuffle("dealer")
- blackjack_shuffle("player")
- # Put number of remaining cards in title bar
- root.title(f'Blackjack - {round(len(deck)/52,2)} Decks Left')
- def dealer_hit():
- global dealer_spot, d_aces, dealer_score, Rc, x
- global player_total, dealer_total, player_score
- global dealer_image0, dealer_image1, dealer_image2, dealer_image3, dealer_image4, dealer_image5
- global dealer_image6, dealer_image7, dealer_image8, dealer_image9, dealer_image10
- if dealer_spot <= 9:
- try:
- # Get the player Card
- dealer_card = random.choice(deck)
- #print(dealer_card)
- # Remove Card From Deck
- deck.remove(dealer_card)
- # Append Card To Dealer List
- dealer.append(dealer_card)
- # Append to dealer score list and convert facecards to 10 or 11
- dcard = int(dealer_card.split("_", 1)[0])
- if dcard == 14:
- dealer_score.append(11)
- elif dcard == 11 or dcard == 12 or dcard == 13:
- dealer_score.append(10)
- else:
- dealer_score.append(dcard)
- if dcard in [10,11,12,13,14]:
- Rc -= 1
- if dcard in [2,3,4,5,6]:
- Rc += 1
- image_path_dealer = resource_path(f'cards/{dealer_card}.png')
- image_path_cover = resource_path(f'cards/{"cover"}.png')
- # Output Card To Screen
- if dealer_spot == 0:
- # Resize Card
- dealer_image1 = resize_cards(image_path_dealer)
- dealer_image0 = resize_cards(image_path_cover)
- # Output Card To Screen
- dealer_label_1.config(image=dealer_image0)
- dealer_spot += 1
- elif dealer_spot == 1:
- # Resize Card
- dealer_image2 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_2.config(image=dealer_image2)
- # Increment our player spot counter
- dealer_spot += 1
- if dcard == 14 and var1.get() == "on":
- insurance()
- elif dealer_spot == 2:
- # Resize Card
- dealer_image3 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_3.config(image=dealer_image3)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 3:
- # Resize Card
- dealer_image4 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_4.config(image=dealer_image4)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 4:
- # Resize Card
- dealer_image5 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_5.config(image=dealer_image5)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 5:
- open_geo()
- # Resize Card
- dealer_image6 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_6.config(image=dealer_image6)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 6:
- # Resize Card
- open_geo()
- dealer_image7 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_7.config(image=dealer_image7)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 7:
- open_geo()
- # Resize Card
- dealer_image8 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_8.config(image=dealer_image8)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 8:
- open_geo()
- # Resize Card
- dealer_image9 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_9.config(image=dealer_image9)
- # Increment our player spot counter
- dealer_spot += 1
- elif dealer_spot == 9:
- open_geo()
- # Resize Card
- dealer_image10 = resize_cards(image_path_dealer)
- # Output Card To Screen
- dealer_label_10.config(image=dealer_image10)
- # Increment our player spot counter
- # Put number of remaining cards in title bar
- root.title(f'Blackjack - {round(len(deck)/52,2)} Decks Left')
- except:
- root.title(f'Blackjack - No Cards In Deck')
- # Check for blackjack
- # blackjack_shuffle("dealer")
- def player_hit():
- global player_spot, p_aces, Rc
- global player_total, dealer_total, player_score
- if player_spot <= 9:
- try:
- # Get the player Card
- player_card = random.choice(deck)
- # Remove Card From Deck
- deck.remove(player_card)
- # Append Card To Dealer List
- player.append(player_card)
- # Append to dealer score list and convert facecards to 10 or 11
- pcard = int(player_card.split("_", 1)[0])
- if pcard == 14:
- player_score.append(11)
- elif pcard == 11 or pcard == 12 or pcard == 13:
- player_score.append(10)
- else:
- player_score.append(pcard)
- if pcard in [10,11,12,13,14]:
- Rc -= 1
- if pcard in [2,3,4,5,6]:
- Rc += 1
- global player_image1, player_image2, player_image3, player_image4, player_image5
- global player_image6, player_image7, player_image8, player_image9, player_image10
- global image_path_player
- image_path_player = resource_path(f'cards/{player_card}.png')
- if player_spot == 0:
- # Resize Card
- player_image1 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_1.config(image=player_image1)
- # Increment our player spot counter
- player_spot += 1
- elif player_spot == 1:
- # Resize Card
- player_image2 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_2.config(image=player_image2)
- # Increment our player spot counter
- player_spot += 1
- elif player_spot == 2:
- # Resize Card
- player_image3 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_3.config(image=player_image3)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 3:
- # Resize Card
- player_image4 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_4.config(image=player_image4)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 4:
- # Resize Card
- player_image5 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_5.config(image=player_image5)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 5:
- # Resize Card
- open_geo()
- player_image6 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_6.config(image=player_image6)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 6:
- # Resize Card
- open_geo()
- player_image7 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_7.config(image=player_image7)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 7:
- # Resize Card
- open_geo()
- player_image8 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_8.config(image=player_image8)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 8:
- # Resize Card
- open_geo()
- player_image9 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_9.config(image=player_image9)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- elif player_spot == 9:
- # Resize Card
- open_geo()
- player_image10 = resize_cards(image_path_player)
- # Output Card To Screen
- player_label_10.config(image=player_image10)
- # Increment our player spot counter
- if split1 == []:
- player_bust()
- player_spot += 1
- # Put number of remaining cards in title bar
- root.title(f'Blackjack - {round(len(deck)/52,2)} Decks Left')
- except:
- root.title(f'Blackjack - No Cards In Deck')
- def split1():
- global player_card, player_score, split_spot, player_spot, split_score
- global split_image1, scard, scard_score, split_card, split1, image_path_sp
- cal_sub()
- t1=int(playerbet1.get())
- sum=t1
- splitbet1.delete(0,END)
- splitbet1.insert(0,int(sum))
- player1_split1 = player[0].split("_", 1)[0]
- player2_split2 = player[1].split("_", 1)[0]
- if player1_split1 == player2_split2:
- split_card = player[1]
- split1.append(split_card)
- player.remove(player[1])
- player_score.remove(player_score[1])
- player_spot -= 1
- scard = int(split_card.split("_", 1)[0])
- if scard == 14:
- split_score.append(11)
- elif scard == 11 or scard == 12 or scard == 13:
- split_score.append(10)
- else:
- split_score.append(scard)
- player_label_2.config(image='')
- image_path_sp = resource_path(f'cards/{split_card}.png')
- if split_spot == 0:
- # Resize Card
- split_image1 = resize_cards(image_path_sp)
- # Output Card To Screen
- split_label_1.config(image=split_image1)
- # Increment our player spot counter
- split_spot += 1
- player_hit()
- split_hit()
- else:
- messagebox.showinfo("", "sorry, can only split pairs")
- split_hit_button.config(state="active")
- split_double_button.config(state="active")
- def split_hit():
- global split_spot, p_aces, Rc, split_frame
- global split_total, dealer_total, player_score
- if split_spot <= 9:
- try:
- # Get the player Card
- split_card = random.choice(deck)
- # Remove Card From Deck
- deck.remove(split_card)
- # Append Card To Dealer List
- split1.append(split_card)
- # Append to dealer score list and convert facecards to 10 or 11
- scard = int(split_card.split("_", 1)[0])
- if scard == 14:
- split_score.append(11)
- elif scard == 11 or scard == 12 or scard == 13:
- split_score.append(10)
- else:
- split_score.append(scard)
- #print(split_card)
- if scard in [10,11,12,13,14]:
- Rc -= 1
- if scard in [2,3,4,5,6]:
- Rc += 1
- global split_image1, split_image2, split_image3, split_image4, split_image5
- global split_image6, split_image7, split_image8, split_image9, split_image10
- global split_label_2, split_label_3, split_label_4, split_label_5, image_path_split
- image_path_split = resource_path(f'cards/{split_card}.png')
- if split_spot == 1:
- # Resize Card
- split_image2 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_2.config(image=split_image2)
- # Increment our player spot counter
- split_spot += 1
- elif split_spot == 2:
- # Resize Card
- split_image3 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_3.config(image=split_image3)
- # Increment our player spot counter
- split_spot += 1
- #blackjack_shuffle("player")
- elif split_spot == 3:
- # Resize Card
- split_image4 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_4.config(image=split_image4)
- # Increment our player spot counter
- split_spot += 1
- #blackjack_shuffle("player")
- elif split_spot == 4:
- # Resize Card
- split_image5 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_5.config(image=split_image5)
- # Increment our player spot counter
- split_spot += 1
- elif split_spot == 5:
- open_geo()
- # Resize Card
- split_image6 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_6.config(image=split_image6)
- # Increment our player spot counter
- split_spot += 1
- elif split_spot == 6:
- open_geo()
- # Resize Card
- split_image7 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_7.config(image=split_image7)
- # Increment our player spot counter
- split_spot += 1
- #blackjack_shuffle("player")
- elif split_spot == 7:
- open_geo()
- # Resize Card
- split_image8 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_8.config(image=split_image8)
- # Increment our player spot counter
- split_spot += 1
- #blackjack_shuffle("player")
- elif split_spot == 8:
- open_geo()
- # Resize Card
- split_image9 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_9.config(image=split_image9)
- # Increment our player spot counter
- split_spot += 1
- elif split_spot == 9:
- open_geo()
- # Resize Card
- split_image10 = resize_cards(image_path_split)
- # Output Card To Screen
- split_label_10.config(image=split_image10)
- # Put number of remaining cards in title bar
- root.title(f'Blackjack - {round(len(deck)/52,2)} Decks Left')
- except:
- root.title(f'Blackjack - No Cards In Deck')
- def run_count():
- global Rc
- messagebox.showinfo("Run Ct", Rc)
- def cal_sub():
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1-t2
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def cal_tie():
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1+t2
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def cal_add():
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1+(t2*2)
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def cal_ace():
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1+(t2*2.5)
- bankroll1.delete(0,END)
- bankroll1.insert(0,int(sum))
- def cal_tie_split():
- t1=int(bankroll1.get())
- t2=int(splitbet1.get())
- sum=t1+t2
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def cal_add_split():
- t1=int(bankroll1.get())
- t2=int(splitbet1.get())
- sum=t1+(t2*2)
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def cal_ace_split():
- t1=int(bankroll1.get())
- t2=int(splitbet1.get())
- sum=t1+(t2*2.5)
- bankroll1.delete(0,END)
- bankroll1.insert(0,int(sum))
- def cal_sub_split():
- t1=int(bankroll1.get())
- t2=int(splitbet1.get())
- sum=t1-t2
- bankroll1.delete(0,END)
- bankroll1.insert(0,sum)
- def player_double():
- cal_sub()
- t2=int(playerbet1.get())
- sum=t2*2
- playerbet1.delete(0,END)
- playerbet1.insert(0,int(sum))
- card_button.config(state="disabled")
- double_button.config(state="disabled")
- player_hit()
- if split1 == [] and player_total <= 21:
- stand()
- def split_double():
- cal_sub_split()
- t3=int(splitbet1.get())
- sum=t3*2
- splitbet1.delete(0,END)
- splitbet1.insert(0,int(sum))
- split_hit_button.config(state="disabled")
- split_double_button.config(state="disabled")
- split_hit()
- def startmoney():
- global data
- data = [] # Initialize data to avoid old values
- mydata_download() # Populate data from the file
- # print(data) # Check the contents of data
- # Ensure there is enough data to access indexes
- if len(data) > 2: # Adjust according to how many items you expect
- if data[2] == "on":
- ck_ins.select() # Assuming ck_ins is defined
- if data[3] == "on":
- ck_H17.select() # Assuming ck_H17 is defined
- # Use default values if data is empty or not as expected
- if len(data) > 0:
- bankroll1.delete(0, END)
- playerbet1.delete(0, END)
- bankroll1.insert(0, data[0])
- playerbet1.insert(0, data[1])
- def player_surrender():
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1 + (t2*.5)
- bankroll1.delete(0,END)
- playerbet1.delete(0,END)
- bankroll1.insert(0,int(sum))
- playerbet1.insert(0,int(0))
- if split1 == []:
- stand()
- def split_surrender():
- t1=int(bankroll1.get())
- t3=int(playerbet1.get())
- sum=t1 + (t3*.5)
- bankroll1.delete(0,END)
- splitbet1.delete(0,END)
- bankroll1.insert(0,int(sum))
- splitbet1.insert(0,int(0))
- def insurance():
- answer = messagebox.askquestion('insurance', 'insurance')
- if answer == "yes":
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1-(t2*.5)
- bankroll1.delete(0,END)
- bankroll1.insert(0,int(sum))
- if answer == "yes" and dealer_score == [10, 11]:
- t1=int(bankroll1.get())
- t2=int(playerbet1.get())
- sum=t1+(t2*1.5)
- bankroll1.delete(0,END)
- bankroll1.insert(0,int(sum))
- blackjack_shuffle()
- if answer == "yes" and dealer_score != [10, 11]:
- blackjack_shuffle()
- if answer == "no":
- blackjack_shuffle()
- def stand():
- global data
- data = []
- if var2.get() == "on":
- stand_H17()
- else:
- stand_S17()
- data = [bankroll1.get(), playerbet1.get(), var1.get() ,var2.get()]
- mydata_upload()
- def mydata_upload():
- global data
- with open('my_list.txt', 'w') as file:
- for item in data:
- file.write(f"{item}\n")
- def mydata_download():
- global data
- try:
- with open('my_list.txt', 'r') as file:
- data = [line.strip() for line in file.readlines()]
- except FileNotFoundError:
- data = ['1000', '20', 'off', 'off']
- my_frame = Frame(root, bg="green")
- my_frame.pack(pady=20)
- # Create Text frame For textboxes
- T_frame = Frame(my_frame, width=1100, height=30, bg="green")
- T_frame.pack_propagate(False)
- T_frame.pack(side=TOP)
- # bankroll1 = bankroll, playerbet1 = bet, splitbet1 = split bet
- label1 = Label(T_frame, text = "Bankroll")
- label1.pack(side=LEFT)
- bankroll1 = Entry(T_frame, width = 15)
- bankroll1.pack(side=LEFT)
- label2 = Label(T_frame, text = "Bet")
- label2.pack(side=LEFT)
- playerbet1 = Entry(T_frame, width = 15)
- playerbet1.pack(side=LEFT)
- label3 = Label(T_frame, text = "Bet")
- splitbet1 = Entry(T_frame, width = 15)
- splitbet1.pack(side=RIGHT)
- label3.pack(side=RIGHT)
- var1 = StringVar()
- var2 = StringVar()
- # Define a Checkbox
- ck_ins = Checkbutton(T_frame, text="Insurance", variable=var1, onvalue="on", offvalue="off")
- ck_ins.pack(side=RIGHT, padx=10)
- ck_H17 = Checkbutton(T_frame, text="hit on soft 17", variable=var2, onvalue="on", offvalue="off")
- ck_H17.pack(side=RIGHT, padx=10)
- ck_ins.deselect()
- ck_H17.deselect()
- # Create Frames For Cards
- dealer_frame = LabelFrame(my_frame, text="", bd=0, bg="green")
- dealer_frame.pack(padx=10, ipadx=0, pady = 10, ipady = 0)
- player_frame = LabelFrame(my_frame, text="", bd=0, bg="green")
- player_frame.pack(padx=10, ipadx=0, pady = 10, ipady = 0)
- split_frame = LabelFrame(my_frame, text="", bd=0, bg="green")
- split_frame.pack(padx=10, ipadx=0, pady = 10, ipady = 0)
- # Put Dealer cards in frames
- dealer_label_1 = Label(dealer_frame, text='', bg="green")
- dealer_label_1.grid(row=0, column=0, pady=5, padx=5)
- dealer_label_2 = Label(dealer_frame, text='', bg="green")
- dealer_label_2.grid(row=0, column=1, pady=5, padx=5)
- dealer_label_3 = Label(dealer_frame, text='', bg="green")
- dealer_label_3.grid(row=0, column=2, pady=5, padx=5)
- dealer_label_4 = Label(dealer_frame, text='', bg="green")
- dealer_label_4.grid(row=0, column=3, pady=5, padx=5)
- dealer_label_5 = Label(dealer_frame, text='', bg="green")
- dealer_label_5.grid(row=0, column=4, pady=5, padx=5)
- dealer_label_6 = Label(dealer_frame, text='', bg="green")
- dealer_label_6.grid(row=0, column=5, pady=5, padx=5)
- dealer_label_7 = Label(dealer_frame, text='', bg="green")
- dealer_label_7.grid(row=0, column=6, pady=5, padx=5)
- dealer_label_8 = Label(dealer_frame, text='', bg="green")
- dealer_label_8.grid(row=0, column=7, pady=5, padx=5)
- dealer_label_9 = Label(dealer_frame, text='', bg="green")
- dealer_label_9.grid(row=0, column=8, pady=5, padx=5)
- dealer_label_10 = Label(dealer_frame, text='', bg="green")
- dealer_label_10.grid(row=0, column=9, pady=5, padx=5)
- # Put Player cards in frames
- player_label_1 = Label(player_frame, text='', bg="green")
- player_label_1.grid(row=1, column=0, pady=5, padx=5)
- player_label_2 = Label(player_frame, text='', bg="green")
- player_label_2.grid(row=1, column=1, pady=5, padx=5)
- player_label_3 = Label(player_frame, text='', bg="green")
- player_label_3.grid(row=1, column=2, pady=5, padx=5)
- player_label_4 = Label(player_frame, text='', bg="green")
- player_label_4.grid(row=1, column=3, pady=5, padx=5)
- player_label_5 = Label(player_frame, text='', bg="green")
- player_label_5.grid(row=1, column=4, pady=5, padx=5)
- player_label_6 = Label(player_frame, text='', bg="green")
- player_label_6.grid(row=1, column=5, pady=5, padx=5)
- player_label_7 = Label(player_frame, text='', bg="green")
- player_label_7.grid(row=1, column=6, pady=5, padx=5)
- player_label_8 = Label(player_frame, text='', bg="green")
- player_label_8.grid(row=1, column=7, pady=5, padx=5)
- player_label_9 = Label(player_frame, text='', bg="green")
- player_label_9.grid(row=1, column=8, pady=5, padx=5)
- player_label_10 = Label(player_frame, text='', bg="green")
- player_label_10.grid(row=1, column=9, pady=5, padx=5)
- # Put Split cards in frames
- split_label_1 = Label(split_frame, text='', bg="green")
- split_label_1.grid(row=2, column=0, pady=5, padx=5)
- split_label_2 = Label(split_frame, text='', bg="green")
- split_label_2.grid(row=2, column=1, pady=5, padx=5)
- split_label_3 = Label(split_frame, text='', bg="green")
- split_label_3.grid(row=2, column=2, pady=5, padx=5)
- split_label_4 = Label(split_frame, text='', bg="green")
- split_label_4.grid(row=2, column=3, pady=5, padx=5)
- split_label_5 = Label(split_frame, text='', bg="green")
- split_label_5.grid(row=2, column=4, pady=5, padx=5)
- split_label_6 = Label(split_frame, text='', bg="green")
- split_label_6.grid(row=2, column=5, pady=5, padx=5)
- split_label_7 = Label(split_frame, text='', bg="green")
- split_label_7.grid(row=2, column=6, pady=5, padx=5)
- split_label_8 = Label(split_frame, text='', bg="green")
- split_label_8.grid(row=2, column=7, pady=5, padx=5)
- split_label_9 = Label(split_frame, text='', bg="green")
- split_label_9.grid(row=2, column=8, pady=5, padx=5)
- split_label_10 = Label(split_frame, text='', bg="green")
- split_label_10.grid(row=2, column=9, pady=5, padx=5)
- # Create Button Frame
- button_frame = Frame(my_frame, width=1100, height=100, bg="green")
- button_frame.pack_propagate(False)
- button_frame.pack()
- # Create a couple buttons
- shuffle_button = Button(button_frame, text="Shuffle Deck", font=("Helvetica", 12), command=shuffle)
- shuffle_button.grid(row=0, column=0)
- card_button = Button(button_frame, text="Player Hit", font=("Helvetica", 12), command=player_hit)
- card_button.grid(row=0, column=1, padx=10)
- double_button = Button(button_frame, text="player double", font=("Helvetica", 12), command=player_double)
- double_button.grid(row=0, column=2, padx=10)
- stand_button = Button(button_frame, text="Stand!", font=("Helvetica", 12), command=stand)
- stand_button.grid(row=0, column=3)
- run_button = Button(button_frame, text="running count", font=("Helvetica", 12), command=run_count)
- run_button.grid(row=2, column=0, padx=10, ipadx=0, pady = 10, ipady = 0)
- split_button = Button(button_frame, text="split", font=("Helvetica", 12), command=split1)
- split_button.grid(row=1, column=0, pady=10)
- split_hit_button = Button(button_frame, text="split hit", font=("Helvetica", 12), command=split_hit)
- split_hit_button.grid(row=1, column=1, pady=10)
- split_double_button = Button(button_frame, text="split double", font=("Helvetica", 12), command=split_double)
- split_double_button.grid(row=1, column=2, pady=10)
- deal_button = Button(button_frame, text="Deal", font=("Helvetica", 12), command=deal)
- deal_button.grid(row=1, column=3, padx=10)
- player_surrender_button = Button(button_frame, text="player surrender", font=("Helvetica", 12), command=player_surrender)
- player_surrender_button.grid(row=2, column=1, padx=10)
- split_surrender_button = Button(button_frame, text="split surrender", font=("Helvetica", 12), command=split_surrender)
- split_surrender_button.grid(row=2, column=2, padx=10)
- # Shuffle Deck On Start
- n_decks = askstring('',"decks")
- startmoney()
- shuffle()
- deal()
- root.mainloop()
- ### put images folder in same folder as python file...
- ### to get running count add 1 for cards 2-6,,, 7,8,9 add 0,,,, 10-Ace subtract 1...
- ### if you divide your running count with the number of decks you have left, you get your true count...
- ### i guess, any true count above 3 you want to start betting heavy
- ### before you decide to go play blackjack for a living, maybe you should watch this first,,, lol...
- ### https://rumble.com/v1frh4h-card-counter-hits-casinos-on-american-road-trip-inside-the-edge-wonder.html
- ### check out my etsy shop: https://www.etsy.com/shop/ExcelByActorkitten
Add Comment
Please, Sign In to add comment