[Pythonmac-SIG] Buttons in W

François Granger fgranger@mail.dotcom.fr
Fri, 23 Mar 2001 17:44:54 +0100


This is my first attempt at using the W module.

As an exercise, I am trying to program the game "TicTacToe".

My idea is to do a set of identical buttons in 3 row by three column. 
My problem is to write a call back function for all these button wich 
can detect wich one was clicked.

some ugly code below, thanks for any input.


import W
w = W.Window((400, 400), "Hello!", minsize = (240, 200))
def bpStart():
	"""
	check radioButton status and set variables accordingly
	"""
	print "Hello World!"

Token = 'O'
def bpCase():
	"""
	handle the click on one location
	"""
	for i in range(3):
		for j in range(3):
			# here i need to get i,j when that is the 
button just clicked.
			print w[i, j]._activated
			if w[i, j]._activated:
				print i,j
				b = i,j
	# here i will use b for other purposes
	w[b]._title = token


stepb = 16
for i in range(3):
	for j in range(3):
		w[i,j] = W.Button((20 + i * stepb,20 + j * 
stepb,stepb,stepb), "X", bpCase)

w.open()
-- 
"Faites des phrases courtes. Un sujet, un verbe, un complément. Quand 
vous voudrez ajouter un adjectif, vous viendrez me voir." - Georges 
Clemenceau, 1841-1929, médecin et homme politique français. Consignes 
aux journalistes de "L'Aurore". d'après 
<http://www.sit.ulaval.ca/pagespersonnelles/phf/pensee.html>