As a learning exercise, I’m coding a Blackjack game which will, in time, follow the correct rules of Blackjack. I have a basic GUI in place, with a single player and I’ve solved all issues related to creating and displaying cards, calculating point and so on.
I now want to add ‘house’ with which to play against. It seems to me (correct me if I’m wrong) that the cardsFrame
is a good candidate for a class
. I could then pass to said class
the string 'Player'
or 'House'
and have class
process the cardsFrame =
part of the script, which the main script would then place
with a relative adjustment to rely
It could be that I don’t need to use class
, but I do want to learn how to use class
.
For now, I feel I need to get this to work with a Function, which could then become a part of a class
, but I’m stuck on the first hop: how to have a Function construct a LabelFrame
with a unique name (one for ‘House’ and one for ‘Player’).
This code is a stripped out working model that simply demonstrates what I’m trying to do, aside from it only constructs a single LabelFrame
named cardsFrame
, but I need it to be a unique name, such as player_cardsFrame
and house_cardsFrame
.
Excuse the Function being named it
– it’s simply a working name.
#!/usr/bin/python3
from tkinter import *
bgColor = "#006400"
cardFrame_w = 400
cardHeight = 80
def it(name):
global cardsFrame
cardsFrame = LabelFrame(tableFrame, width=cardFrame_w, height=cardHeight+30, bg=bgColor, text=name)
root = Tk()
root.geometry("800x400")
root.title("Blackjack")
root.resizable(False, False)
# table set-up
tableFrame = Frame(root, width=800, height=400, bg=bgColor)
tableFrame.place(relx = 0.001, rely = 0.001)
# card container set-up
name = input("Name: ")
it(name)
'''this has been moved to a Function
cardsFrame = LabelFrame(tableFrame, width=cardFrame_w, height=cardHeight+30, bg=bgColor, text=name)
'''
cardsFrame.place(relx=0.01, rely=0.02)
root.mainloop()