O'Reilly logo

A Concise Introduction to Programming in Python by Mark J. Johnson

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

Chapter 28

Graphical User Interfaces

Most software written today uses a graphical user interface (GUI) rather than the text-based interface we have used in most of our examples. In this chapter, we rewrite the Chuck-a-Luck program from Chapter 24 to use a graphical interface.

Listing 28.1: Chuck-a-Luck (GUI Version)

 1 # chuckgui.py
 2
 3 from dicegui import DiceGUI
 4 from tkinter import *
 5
 6 class ChuckALuckGUI(Frame):
 7 def __init__(self, parent):
 8  Frame.__init__(self, parent)
 9  parent.geometry("500×300")
10  parent.title("Chuck-A-Luck")
11  self.dice = DiceGUI(3, self)
12  self.dice.pack(fill="y", expand=True)
13  self.score = 0
14  self.makecontrols()
15  self.makescore()
16  self.pack(fill="y", expand=True)
17
18 def makecontrols(self): ...

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