Newbie Question

2005-12-05 Thread solaris_1234
I am trying to learn Python and I have a few questions.

I have created a Class that is essentially a canvas with a red
background. After creation I want to change the background to green.
However I am having problems doing this. 

Here is my code:

from Tkinter import *

class MyApp:
   def __init__(self, parent):
self.myParent = parent
self.myContainer = Frame(parent)
self.myContainer.pack()

self.b1 = Canvas(self.myContainer, background="red").grid(row=0,
column=0)

def ChangebgColor(self):
   self(bg="green")


root = Tk()
myapp=MyApp(root) #Everything is fine at this point.

raw_input()

ChangebgColor(myapp.b1) # Error Message at this point

raw_input()



Any help will be greatly appreciated.



-- 
http://mail.python.org/mailman/listinfo/python-list


Another newbie question

2005-12-07 Thread solaris_1234
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