O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Card, Deck, and Hand

First, copy over the Card class from the code you wrote for Chapter 2, Back to the Command Line - Basic Blackjack. There are no changes to the existing methods in this class, but we need to add one more for our graphical implementation:

@classmethoddef get_back_file(cls):    cls.back = tk.PhotoImage(file=assets_folder + "/back.png")    return cls.back

This new method will use a decorator to make it into a class method. A class method functions much like a regular method (or function), except that it does not require an instance of the class to work.

For this reason, we name the first variable cls instead of self. Python will automatically pass a reference to the class itself to a class method, meaning just as is the case with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required