I am doing my major work for SDD and i am making checkers, i have searched and tried many differnt solutions but nothing has worked, i am trying to make the window size set to 800x800 and have "Checkers" as a title and 4 buttons down the bottom, i would like to have a space between checkers and the 4 buttons but i have had no luck so far.

here is my code

from Tkinter import *
import Tkinter as tk
        
def startMenu():
    top = tk.Tk()
    top.title("Checkers")
    top = tk.Canvas(width="800", height="800")
##    top.geometry("800x800")
    top.pack(fill='both', expand='yes')
    square1 = top.create_rectangle(0,0,100,100, fill="white")
    square2 = top.create_rectangle(100,0,200,100, fill="black")
    square3 = top.create_rectangle(200,0,300,100, fill="white")
    square4 = top.create_rectangle(300,0,400,100, fill="black")
    square5 = top.create_rectangle(400,0,500,100, fill="white")
    square6 = top.create_rectangle(500,0,600,100, fill="black")
    square7 = top.create_rectangle(600,0,700,100, fill="white")
    square8 = top.create_rectangle(700,0,800,100, fill="black")
    square9 = top.create_rectangle(0,100,100,200, fill="black")
    square10 = top.create_rectangle(100,100,200,200, fill="white")
    square11 = top.create_rectangle(200,100,300,200, fill="black")
    square12 = top.create_rectangle(300,100,400,200, fill="white")
    square13 = top.create_rectangle(400,100,500,200, fill="black")
    square14 = top.create_rectangle(500,100,600,200, fill="white")
    square15 = top.create_rectangle(600,100,700,200, fill="black")
    square16 = top.create_rectangle(700,100,800,200, fill="white")
    square17 = top.create_rectangle(0,200,100,300, fill="white")
    square18 = top.create_rectangle(100,200,200,300, fill="black")
    square19 = top.create_rectangle(200,200,300,300, fill="white")
    square20 = top.create_rectangle(300,200,400,300, fill="black")
    square21 = top.create_rectangle(400,200,500,300, fill="white")
    square22 = top.create_rectangle(500,200,600,300, fill="black")
    square23 = top.create_rectangle(600,200,700,300, fill="white")
    square24 = top.create_rectangle(700,200,800,300, fill="black")
    square25 = top.create_rectangle(0,300,100,400, fill="black")
    square26 = top.create_rectangle(100,300,200,400, fill="white")
    square27 = top.create_rectangle(200,300,300,400, fill="black")
    square28 = top.create_rectangle(300,300,400,400, fill="white")
    square29 = top.create_rectangle(400,300,500,400, fill="black")
    square30 = top.create_rectangle(500,300,600,400, fill="white")
    square31 = top.create_rectangle(600,300,700,400, fill="black")
    square32 = top.create_rectangle(700,300,800,400, fill="white")
    square33 = top.create_rectangle(0,400,100,500, fill="white")
    square34 = top.create_rectangle(100,400,200,500, fill="black")
    square35 = top.create_rectangle(200,400,300,500, fill="white")
    square36 = top.create_rectangle(300,400,400,500, fill="black")
    square37 = top.create_rectangle(400,400,500,500, fill="white")
    square38 = top.create_rectangle(500,400,600,500, fill="black")
    square39 = top.create_rectangle(600,400,700,500, fill="white")
    square40 = top.create_rectangle(700,400,800,500, fill="black")
    square41 = top.create_rectangle(0,500,100,600, fill="black")
    square42 = top.create_rectangle(100,500,200,600, fill="white")
    square43 = top.create_rectangle(200,500,300,600, fill="black")
    square44 = top.create_rectangle(300,500,400,600, fill="white")
    square45 = top.create_rectangle(400,500,500,600, fill="black")
    square46 = top.create_rectangle(500,500,600,600, fill="white")
    square47 = top.create_rectangle(600,500,700,600, fill="black")
    square48 = top.create_rectangle(700,500,800,600, fill="white")
    square49 = top.create_rectangle(0,600,100,700, fill="white")
    square50 = top.create_rectangle(100,600,200,700, fill="black")
    square51 = top.create_rectangle(200,600,300,700, fill="white")
    square52 = top.create_rectangle(300,600,400,700, fill="black")
    square53 = top.create_rectangle(400,600,500,700, fill="white")
    square54 = top.create_rectangle(500,600,600,700, fill="black")
    square55 = top.create_rectangle(600,600,700,700, fill="white")
    square56 = top.create_rectangle(700,600,800,700, fill="black")
    square57 = top.create_rectangle(0,700,100,800, fill="black")
    square58 = top.create_rectangle(100,700,200,800, fill="white")
    square59 = top.create_rectangle(200,700,300,800, fill="black")
    square60 = top.create_rectangle(300,700,400,800, fill="white")
    square61 = top.create_rectangle(400,700,500,800, fill="black")
    square62 = top.create_rectangle(500,700,600,800, fill="white")
    square63 = top.create_rectangle(600,700,700,800, fill="black")
    square64 = top.create_rectangle(700,700,800,800, fill="white")
    label1 = tk.Label(top, text = 'Checkers', font=('Arial', 36))
    label1.pack()
    button1 = tk.Button(top, text = "Start", relief=FLAT, font=('Arial', 26))
    button1.pack()
    button2 = tk.Button(top, text = "Help", relief=FLAT, font=('Arial', 26))
    button2.pack()
    button3 = tk.Button(top, text = "Options", relief=FLAT, font=('Arial', 26))
    button3.pack()
    button4 = tk.Button(top, text="Quit", relief=FLAT, command=quit, font=('Arial', 26), anchor = 'center')
    button4.pack()
        
    top.mainloop()
    
startMenu()

Any help here will be greatly appreciated.

Recommended Answers

All 4 Replies

You can not mix canvas and grid. To use a label, button, etc. you must add a frame to the canvas. The following example will get you started on this, as well as using a for loop to create the square.

##-------  Do not import Tkinter twice; use one or the other
from Tkinter import *
##import Tkinter as tk
 
def startMenu():
    top_tk = Tk()
    top_tk.title("Checkers")
    top = Canvas(width="800", height="800")

    square_list = []
    color = "white"
    for j in range(0, 701, 100):
        square_list.append(top.create_rectangle(j,0,j+100,100, fill=color))
        if color == "white":
            color = "black"
        else:
            color = "white"

    fr = Frame(top, relief=GROOVE, borderwidth=2)
    label1 = Label(fr, text='Checkers', font=('Arial', 36), fg="blue")
    label1.pack(side="left")

    top.create_window(210, 800, window=fr, anchor=SE)
    top.pack(fill='both', expand='yes')
 
    top.mainloop()
 
startMenu()
commented: Thanks alot! helped greatly +0

Create a Tkinter.Frame to hold the checker board and another frame to hold the buttons. Pack the frames "top". If you want the buttons along the bottom, pack "left". Add internal padding to each frame to get the desired space.

To eliminate duplication, initialize a list and iterate on columns and rows.

size = 50
    cols = 8
    rows = 8
    squareList = []
    for i in range(cols):
        for j in range(rows):
            if j%2: colors = ["black", "white"]
            else: colors = ["white", "black"]
            squareList.append(top.create_rectangle(i*size,  j*size,
                                                   i*size+size, j*size+size,
                                                   fill=colors[i%2]))

Thank you all for helping me, i have a funny feeling i will need more help later on though.

why are you using tkinter for a game, use pygame

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.