I was wondering how to make more columns in this program in python. ''' from tkinter import * window = Tk() nrows = 3 # X and O rows ncols = 3# X and O colums bg_color = 'gray32' #Board Color label_font = ('Helvetica', '12', 'bold') message_font = ('Helvetica', '18', 'bold') #get the images im_Empty = PhotoImage(file="brushwalker437b-128px.png") on_move_image = im_X = PhotoImage(file="hiclipart-com-X1-128px.png") off_move_image = im_O = PhotoImage(file="hiclipart-com-O1-128px.png") square_width = im_Empty.width() square_height = im_Empty.height() # -------------------------------------------------------------------------------------- # Make a Frame with a border to contain the canvas # row = Frame(window, height=1, bd=8, relief=RAISED, bg=bg_color) row.pack(side=TOP, fill=X, padx=0, pady=0) # -------------------------------------------------------------------------------------- # Create the canvas and background image # canvas = Canvas(row, width = square_width, height = square_height, bg = bg_color, bd=0, highlightthickness=0, relief='ridge') canvas.create_image(0, 0, image = im_Empty, anchor = 'nw') canvas.update() 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('', on_mouse_press) window.title('Tic Tac Toe') window.mainloop()
I was wondering how to make more columns in this program in python.
'''
from tkinter import *
window = Tk()
nrows = 3 # X and O rows
ncols = 3# X and O colums
bg_color = 'gray32' #Board Color
label_font = ('Helvetica', '12', 'bold')
message_font = ('Helvetica', '18', 'bold')
#get the images
im_Empty = PhotoImage(file="brushwalker437b-128px.png")
on_move_image = im_X = PhotoImage(file="hiclipart-com-X1-128px.png")
off_move_image = im_O = PhotoImage(file="hiclipart-com-O1-128px.png")
square_width = im_Empty.width()
square_height = im_Empty.height()
# --------------------------------------------------------------------------------------
# Make a Frame with a border to contain the canvas
#
row = Frame(window, height=1, bd=8, relief=RAISED, bg=bg_color)
row.pack(side=TOP, fill=X, padx=0, pady=0)
# --------------------------------------------------------------------------------------
# Create the canvas and background image
#
canvas = Canvas(row, width = square_width, height = square_height,
bg = bg_color, bd=0, highlightthickness=0, relief='ridge')
canvas.create_image(0, 0, image = im_Empty, anchor = 'nw')
canvas.update()
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('<Button-1>', on_mouse_press)
window.title('Tic Tac Toe')
window.mainloop()
Step by step
Solved in 3 steps with 3 images