-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathEX9.6.py
21 lines (19 loc) · 813 Bytes
/
EX9.6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 9.6 (Game: display a tic-tac-toe board ) Write a program that displays nine labels.
# Each label may display an image icon for an X or an image icon for an O, as
# shown in Figure 9.25b. What to display is randomly decided. Use the
# random.randint(0, 1) function to generate an integer 0 or 1, which corresponds
# to displaying a cross image (X) icon or a not image (O) icon. The cross and
# not images are in the files x.gif and o.gif.
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)
window.mainloop()