Question
Hi I need to modify this program with two variables, nrows and ncols that represent a number of rows and columns. I need to use
Hi I need to modify this program with two variables, nrows and ncols that represent a number of rows and columns. I need to use nested for loops to tile a square image over an enlarged canvas. The part I added is with the for loop. I am trying to figure out how to repeat the image in a grid pattern for a tic tac toe game.
This is what I have so far:
from tkinter import * window = Tk()
nrows = 3 ncols = 3
bg_color = 'gray32' label_font = ('Helvetica', '12', 'bold') message_font = ('Helvetica', '18', 'bold')
#get the images im = PhotoImage(file="back.png") im_X = PhotoImage(file="x.png") im_O = PhotoImage(file="o.png")
image_width = im.width() image_height = im.height()
# -------------------------------------------------------------------------------------- # Make a Frame with a border to contain the canvas # row = Frame(window, height=1, bd=3, relief=RAISED, bg=bg_color) row.pack(side=TOP, fill=X, padx=0, pady=0)
# -------------------------------------------------------------------------------------- # Ask the user how many rows and columns to make. # canvas = Canvas(row, width = image_width, height = image_height, bg = bg_color, bd=0, highlightthickness=0, relief='ridge')
for r in range(nrows): for c in range(ncols): r=Image.Open(im) c=Image.Open(im) r=im c=im canvas.create_image(0, 0, image = im, anchor = 'nw') print('('+str(r)+','+str(c)+')',end='') print()
canvas.update() on_move_image = im_X off_move_image = im_O
canvas.pack()
#---------------------------------------------------------------------------------------- # Add a row at botom for label, button row = Frame(window, height=50, bd=4, relief=RAISED, bg=bg_color) row.pack(side=TOP, fill=X, padx=0, pady=0)
def new_game(): print('New Game') #---------------------------------------------------------------------------------------- # New Game Button Button(row, fg ="white", bg = bg_color , text = "New Game", font=label_font, command = new_game, height=1, bd=8, relief=RAISED).pack(side=LEFT, expand=NO, fill=X)
#---------------------------------------------------------------------------------------- # Message Label l_msg = Label(row, text = '', width=10, font=message_font, anchor=CENTER, height=1, bd=8, relief=RAISED, bg=bg_color, fg='white', pady=0) l_msg.pack(side=LEFT, expand=YES, fill=X)
def on_mouse_press(event): print('Mouse Pressed')
print('New Game')
canvas.bind('
def on_closing(): window.destroy()
canvas.bind('
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started