Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 397: 11.49

Answer

code

Work Step by Step

# 11.49 (Game: display a tic-tac-toe board) Revise Exercise 9.6 to display a new tic-tac-toe # board with a click of the Refresh button, as shown in Figure 11.19. import random from tkinter import * window = Tk() x = PhotoImage(file="x.gif") o = PhotoImage(file="o.gif") for i in range(3): for j in range(3): r = random.randint(0, 1) if r == 0: Label(window, image=x).grid(row=i + 1, column=j + 1) elif r == 1: Label(window, image=o).grid(row=i + 1, column=j + 1) def refresh(): for i in range(3): for j in range(3): r = random.randint(0, 1) if r == 0: Label(window, image=x).grid(row=i + 1, column=j + 1) elif r == 1: Label(window, image=o).grid(row=i + 1, column=j + 1) Button(window, text='Refresh', command=refresh).grid(row=4, column=2) window.mainloop()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.