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

The GameScreen class

Our GameScreen class will hold the window attributes for our game as well as all of the graphical widgets. It makes sense for us to make this the main window of our application too, so we will inherit from the Tk widget in order to do this. Let's have a look at how we are going to set up our application:

class GameScreen(tk.Tk):    def __init__(self):        super().__init__()        self.title("Blackjack")        self.geometry("800x640")        self.resizable(False, False)

We begin by initializing the Tk superclass. This ensures all of our graphical elements behave as they should.

We set the title of our application to Blackjack. If you can think of a quirkier name for the application, then feel free to change this!

The geometry method of a Tk widget ...

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