[Tutor] lambda
anthonym
anthonym at att.net
Sat Jan 26 00:57:51 CET 2013
Hello All,
I have the code below that I used to create a simple tic tac toe game for
class. I am learning Python but have programmed in C+ before so I brought
over a lambda and found that it worked in Python. Unfortunately I don't
think my classmates will understand the use of lambda here but I am having
are hard time converting that to strictly python.
Let me know if it can be done.
Thanks
from tkinter import *
def ttt(r,c):
global player
if player == 'X':
b[r][c].configure(text = 'X')
player = 'O'
else:
b[r][c].configure(text = 'O')
player = 'X'
root = Tk()
b = [[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
for i in range(3):
for j in range(3):
b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
command = lambda r=i,c=j: ttt(r,c))
b[i][j].grid(row = i, column = j)
player = 'X'
mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130125/423fdb0a/attachment.html>
More information about the Tutor
mailing list