I am a python newbie and have been trying to learn python. To this end, I have coded the following program creates: a 8 by 8 checker board Places two checkers on the board Checks the board and prints out which squares has a checker on them.
It works. But I have a one question: 1) The stmt "board.Blist[10].DrawQueen(board.Blist[10].b1)" seems awkward. Is there another way (cleaner, more intuitive) to get the same thing done? I appreciate any and all input on how the following program could be improved. from Tkinter import * import time totalSolutionCount = 0 class MyBox: def __init__(self, myC, myrow, mycolumn, color): self.b1 = Canvas(myC, background=color, width=50, height=50) self.b1.grid(row=myrow, column=mycolumn) self.occupied = 0 def ChangebgColor(self, box): box.config(bg="black") def DrawQueen(self, box): box.item = box.create_oval(4,4,50,50,fill="black") self.occupied = 1 box.update() def unDrawQueen(self, box): box.delete(box.item) self.occupied = 0 box.update() class MyBoard(MyBox) : def __init__(self, myC): self.Blist = [] count=0 for i in range(8): count += 1 for j in range(8): count += 1 if (count%2): self.Blist.append(MyBox(myContainer,i,j, "red")) else: self.Blist.append(MyBox(myContainer,i,j, "green")) root=Tk() myContainer = Frame(root) myContainer.pack() board=MyBoard(myContainer) board.Blist[10].DrawQueen(board.Blist[10].b1) board.Blist[22].DrawQueen(board.Blist[22].b1) raw_input() # A Hack debug statement for i in range(64): if board.Blist[i].occupied == 1: print i, "is occupied" raw_input() # A Hack debug statement print "\n"*3 -- http://mail.python.org/mailman/listinfo/python-list