please help
Reshmi Nath
reshminath_1999 at yahoo.com
Fri Nov 29 00:11:02 EST 2002
hi
i am really new to python and Tkinter.I was writting this game where you have a screen with 100 buttons(its the screen class).Its a 2 player game so the buttons should display the 2 different symbols alternately,and also when abutton is clicked the appropriate position in an array in the board class should change to 1 or 2.So that i can write a function that would check if there is a winner (which is when we have 5 in a row).I wrote a program which i thought would worklike that but its giving me errors .I am attaching a copy of the program here.please help I am really desparate.I also want to know what exactly does the mainloop do?
Thanks Reshmi.
from Tkinter import*
class Board:
def __init__(self):
self.mat = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
self.tok1 = 10
self.tok2 = 10
def printIt(self):
print self.mat
class but:
def __init__(self,master,row,col):
self.button=Button(master,text = ' ',command=self.clicked(row,col))
self.index = 0
self.b = Board()
def clicked(self,row,col):
self.index = self.index+1
print self.index
if self.b.tok1 > 0 and self.b.tok2 > 0: # each time a button is clicked alternate
if self.index%2 == 0: # signs should display
self.button.configure(text = '#')
self.b.tok1 = self.b.tok1-1
b.mat[row][col]=1 # when the button is clicked appropriate position
elif self.index%2 != 0: # in b.mat should change to 1 or 2
self.button.configure(text = '&')
self.b.tok2 = self.b.tok2-1
b.mat[row][col]= 2
def unClicked(self):
self.button.configure(text =' ')
def allign(self,i,j):
self.button.grid(row=i,column=j)
def game():
root = Tk()
app = Screen(root)
root.mainloop()
# output the board with 100 buttons
class Screen:
def __init__(self,master):
frame = Frame(master)
frame.pack()
self.index = 0
self.list = [None]*100
self.index=0
for i in range(10):
for j in range(10):
self.temp=but(frame,i,j)
self.temp.allign(i,j)
self.list[self.index]=self.temp
self.index = self.index+1
if __name__== '__main__':
game()
---------------------------------
With Yahoo! Mail you can get a bigger mailbox -- choose a size that fits your needs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20021129/de96200a/attachment.html>
More information about the Python-list
mailing list