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

Running out of money

As the rounds go on, the amount of money needed to satisfy the minimum bet will grow. This means that if the player loses enough rounds, they will be unable to continue playing.

When this happens, the GameScreen will call the on_game_over method within our GameWindow so that it can adjust the GUI elements accordingly:

def on_game_over(self):    self.hit_button.pack_forget()    self.stick_button.pack_forget()    self.new_game_button.pack(side=tk.LEFT, padx=(100, 200))    self.quit_button.pack(side=tk.LEFT)

The hit and stick buttons are replaced with a new game button as well as our familiar quit button. The new game button will call a method named new_game on our GameWindow:

def new_game(self):    self.remove_all_buttons()    self.game_screen.refresh() ...

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