To make and display a window for our game, we just need an instance of our GameScreen
. Since this inherits from the Tk
widget, we will also need to call its mainloop
method to make it show.
We will do this within an if __name__ == "__main__"
block to allow our classes from this file to be imported into another, in case someone wanted to write another card game using our Card
and Deck
classes, for example:
if __name__ == "__main__": gs = GameScreen() gs.mainloop()
Add the preceding code to the very bottom of your code file of this chapter and run the program. You should now have a fully working game of blackjack:
Our game of blackjack
Hopefully, you will agree that this is much more enjoyable than the command-line version. Feel free to have a play around with any of the constants, colors, or image files in order to make the game more personal to you.