I'm new to python and committing to a project to help myself learn so I'm sure this isn't the best way to write any of this. But I'm trying to get a third label to show up as an image of a randomized card after using a "hit" button in blackjack. The Label is appearing in the window, because the window expands, but its empty, and I'm unsure why.
This is my current code, deleted some less important stuff thats not relevant. So im trying to use the length of the hand list to determine which label to give an image and pack, as Ill have a couple more once I get the third figured out..right now it just shows up as a blank white label, while the initial 2 show up fine.
from tkinter import *
import random
def new_turn(hand):
for x in range(2):
hand.append(random.choice(list(num.keys())))
hand.append(random.choice(type))
def hit(hand):
hand.append(random.choice(list(num.keys())))
hand.append(random.choice(type))
length = len(hand)
image = PhotoImage(file=f"BlackJack cards\\{hand[(length - 2)]} {hand[(length - 1)]}.png")
if length == 6:
hand_three.config(image=image)
hand_three.pack(side=TOP)
window = Tk()
type = ("Spades", "Clubs", "Hearts", "Diamonds")
num = {"A":11,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"J":10,"Q":10,"K":10}
p_hand = []
new_turn(p_hand)
p_hand_one_image = PhotoImage(file=f"BlackJack cards\\{p_hand[0]} {p_hand[1]}.png")
p_hand_two_image = PhotoImage(file=f"BlackJack cards\\{p_hand[2]} {p_hand[3]}.png")
hand_one = Label(window,image=p_hand_one_image)
hand_one.pack(side=TOP)
hand_two = Label(window,image=p_hand_two_image)
hand_two.pack(side=TOP)
hand_three = Label(window,image="")
hit_button = Button(window,text="Hit",command=lambda: hit(p_hand))
hit_button.pack(side=BOTTOM)
window.mainloop()